当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET的四种错误机制

ASP.NET
也说C#实现对Word文件读写
字符串处理:中英文混排固定长度截取问题
用asp.net还原与恢复sqlserver数据库
C#加密路径里的参数,保护参数隐私安全!
ASP.NET实现网络空间管理
Asp.net中处理共享Session的问题
ASP.NET之精通弹出窗口
禁止在TextBox中输入
将一个图片以二进制值的形式存入Xml文件中
vs.net 2003在FAT32格式的系统中安装
.Net FrameWork SDK文档的例子演示
改善C#中socket通信机客户端程序的健壮性
C#中的域(field)和属性(property)
将ASP.net中的Table中的数据导入到Execl
C#中的数组和C++中数组的区别
C#中的checked、unchecked操作符
asp.net 的 Request对象
C#中方法参数的四种类型
C#中的“装箱”与“拆箱”
C#中的代理(delegate)

ASP.NET的四种错误机制


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 129 ::
收藏到网摘: n/a

  摘自CNblogs Fantasy Soft的文章:

  1,Webconfig设置

  <?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>

  2,Global.asax设置

  protected void Application_Error(object sender, EventArgs e) {
  Exception objErr = Server.GetLastError().GetBaseException();
  Response.Write("Error:" + objErr.Message);
  Server.ClearError();
  }

  3,使用ErrorPage属性

  <script language="C#" runat="server">
  protected void Page_Load(object sender, EventArgs e) {
        this.ErrorPage = "ErrorPage.htm";
        }  
  </script>

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

  根据优先级从高到低排序:Page_Error事件处理方法 > ErrorPage属性 > Application_Error事件处理方法 >  <customErrors>配置项。