在Asp.net中自定义异常页面 - 编程吧

上一篇 | 下一篇

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

发布: 2006-8-23 21:41 | 作者: 未知 | 来源: 网络 | 查看: 111次

按异常处理优先级排序
  (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中设置异常处理页

TAG: 编程

字号: | 推荐给好友

 

评分:0

我来说两句

seccode