• 在Asp.net中自定义异常页面


    按异常处理优先级排序
      (0)在Global.asax的Application_Error添加代码
        protected void Application_Error(Object sender, EventArgs e)
        {
            Context.ClearError();
            Response.Write("Error");
            Response.Redirect("errorpage.htm");
        }

      (1)后台代码中的WebForm1_Error
         aspx页面的属性中UI.Page的Error事件中添加异常处理代码
         private void WebForm1_Error(object sender, System.EventArgs e)
         {
            Exception ex=Server.GetLastError();
            Session["error"]=ex.Message;
            Server.ClearError();
            Response.Redirect("error.aspx");
         }
      (2)在html代码中加入ErrorPage
         ErrorPage="http://www.21cn.com"
      (3)在Web.config中添加异常处理的页面
        <customErrors mode="On" defaultRedirect="error.aspx">
        <error statusCode="401" redirect="error.aspx"/>
        <error statusCode="404" redirect="http://www.sina.com.cn"/>
        </customErrors>
      (4)在IIS中设置异常处理页
  • 相关阅读:
    原生js大总结十一
    jQuery快速入门知识重点
    原生js大总结九
    原生js大总结十
    原生js大总结八
    原生js大总结六
    原生js大总结七
    原生js大总结四
    原生js大总结五
    移动端适配
  • 原文地址:https://www.cnblogs.com/King0502/p/2019367.html
Copyright © 2020-2023  润新知