asp.net intercepts 404 errors in global

  • 2020-05-07 19:32:52
  • OfStack


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

Related articles: