Global.asax ile Hata Denetimi

void Application_Error(object sender, EventArgs e)
{
app_LogRequest(sender, e);
}

void app_LogRequest(object sender, EventArgs e)
{
Exception ex = Context.Server.GetLastError();
string action=string.Empty;

HttpException httpException = ex as HttpException;
if (httpException!=null){
switch (httpException.GetHttpCode())
{
case 404:
// page not found
action = “HttpError404”;
Response.RedirectPermanent(“/hata?kod=404”);
break;
case 500:
// server error
action = “HttpError500”;
break;
default:
action = “General”;
break;
}
}