当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net 在global中拦截404错误的实现方法

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:void application_error(object sender, eventargs e) { if(context != null) { h
复制代码 代码如下:

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);
}
}
}
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网