html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

ASP.NET的四种错误机制_.NET教程_编程技术

[ ] 已经帮助:人解决问题

  摘自CNblogs Fantasy Soft的文章: APLHTML5中文学习网 - HTML5先行者学习网

  1,Webconfig设置 APLHTML5中文学习网 - HTML5先行者学习网

  <?xml version="1.0"?>
    <configuration>
  <system.web>
  <customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
  <error statusCode="403" redirect="Error403.htm" />
  <error statusCode="404" redirect="Error404.htm" /> 
  </customErrors>
  </system.web>
  </configuration>
APLHTML5中文学习网 - HTML5先行者学习网

  2,Global.asax设置 APLHTML5中文学习网 - HTML5先行者学习网

  protected void Application_Error(object sender, EventArgs e) {
  Exception objErr = Server.GetLastError().GetBaseException();
  Response.Write("Error:" + objErr.Message);
  Server.ClearError();
  }
APLHTML5中文学习网 - HTML5先行者学习网

  3,使用ErrorPage属性 APLHTML5中文学习网 - HTML5先行者学习网

  <script language="C#" runat="server">
  protected void Page_Load(object sender, EventArgs e) {
        this.ErrorPage = "ErrorPage.htm";
        }  
  </script>
APLHTML5中文学习网 - HTML5先行者学习网

  4,使用Page_Error事件处理方法
  protected void Page_Error(object sender, EventArgs e) {
  Exception objErr = Server.GetLastError().GetBaseException();
  Response.Write("Error:" + objErr.Message);
  Server.ClearError(); //同样要注意这句代码的使用
  } 
APLHTML5中文学习网 - HTML5先行者学习网

  根据优先级从高到低排序:Page_Error事件处理方法 > ErrorPage属性 > Application_Error事件处理方法 >  <customErrors>配置项。 APLHTML5中文学习网 - HTML5先行者学习网

APLHTML5中文学习网 - HTML5先行者学习网

APLHTML5中文学习网 - HTML5先行者学习网
APLHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助