ASP.NET的四种错误机制

来源:互联网 发布:应届程序员被辞退 编辑:程序博客网 时间:2024/05/07 07:44
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
.Bxk842{display:none;}

1,Webconfig设置

<?xmlversion="1.0"?>
 <configuration>
<system.web>
<customErrorsmode="On"defaultRedirect="GenericErrorPage.htm">
<errorstatusCode="403"redirect="Error403.htm"/>
<errorstatusCode="404"redirect="Error404.htm"/> 
</customErrors>
</system.web>
</configuration>

2,Global.asax设置

protectedvoidApplication_Error(objectsender,EventArgse){
ExceptionobjErr=Server.GetLastError().GetBaseException();
Response.Write("Error:"+objErr.Message);
Server.ClearError();
}

3,使用ErrorPage属性

<scriptlanguage="C#"runat="server">
protectedvoidPage_Load(objectsender,EventArgse){
       this.ErrorPage="ErrorPage.htm";
       }  
</script>

4,使用Page_Error事件处理方法
protectedvoidPage_Error(objectsender,EventArgse){
ExceptionobjErr=Server.GetLastError().GetBaseException();
Response.Write("Error:"+objErr.Message);
Server.ClearError();//同样要注意这句代码的使用

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击