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

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

按异常处理优先级排序

(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中设置异常处理页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航