asp.net系统错误处理

第一步:在web.config中 
 
<configuration>
<system.web>
    <!--错误页面跳转-->
    <customErrors mode="On" defaultRedirect="">
      <error statusCode="403" redirect=""/>
      <error statusCode="404" redirect=""/>
    </customErrors>
</system.web>
</configuration>

第二步:在Global.asax中

        private void Application_Error(object sender, EventArgs e)
        {
            // 在出现未处理的错误时运行的代码
            Exception ex = null;
            Server.GetLastError();
            if (ex is HttpException)
            {
                if (((HttpException)(ex)).GetHttpCode()==404)
                {
                    Server.Transfer("Right.aspx", false);
                }
            }
        }

猜你喜欢

转载自blog.csdn.net/weixin_39550799/article/details/80775116
今日推荐