asp.net 在global中拦截404错误的实现方法
时间:2021-08-26 08:14:13|栏目:.NET代码|点击: 次
复制代码 代码如下:
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);
}
}
}
}
上一篇:C# goto语句的具体使用
栏 目:.NET代码
本文标题:asp.net 在global中拦截404错误的实现方法
本文地址:http://www.codeinn.net/misctech/170114.html






