您的位置:首页 > 其它

自定义错误页面

2009-01-24 10:07 302 查看
在Web.config中:

<customErrors mode ="On" defaultRedirect="~/ErrorCustom.aspx" />

customErrors mode ="On" 服务器和客户端都显示自定义错误页面

customErrors mode ="RemoteOnly" 服务器使用标准的错误页面,客户端显示自定义错误页面

在Global.asax中:

protected void Application_Error(object sender, EventArgs e)
{
if (Context != null && Context.IsCustomErrorEnabled)
{
Server.Transfer("ErrorCustom.ASPX", false);
}
}

在ErrorCustion.ASPX中:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Exception ex = Server.GetLastError().GetBaseException();
Label1.Text = ex.Message;
Server.ClearError();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: