首页 > 编程 > .NET > 正文

asp.net 在global中拦截404错误的实现方法

2020-01-18 00:55:33
字体:
来源:转载
供稿:网友
复制代码 代码如下:

void Application_Error(object sender, EventArgs e)
{
if(Context != null)
{
HttpContext ctx = HttpContext.Current;
Exception ex = ctx.Server.GetLastError();
HttpException ev = ex as HttpException;
if(ev!= null)
{
if(ev.GetHttpCode() == 404)
{
ctx.ClearError();
Response.Redirect("~/nofound.aspx", false);
Response.End();
}
else
{
Server.Transfer("~/Error.aspx", false);
}
}
}
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表