- 时间:2020-12-28 15:58 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:asp.net 在global中拦截404错误的实现方法
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);
}
}
}
}