zoukankan      html  css  js  c++  java
  • 在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中设置异常处理页
  • 相关阅读:
    8组-Alpha冲刺-2/6
    8组-Alpha冲刺-1/6
    8组 需求分析报告
    结对编程作业
    8组 团队展示
    第一次个人编程作业
    第一次博客作业
    面向对象程序设计寒假作业3
    面向对象程序设计寒假作业2
    面向对象程序设计寒假作业1
  • 原文地址:https://www.cnblogs.com/King0502/p/2019367.html
Copyright © 2011-2022 走看看