protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
switch (httpException.GetHttpCode())
{
case 404:
Response.Redirect("default.aspx");
break;
case 500:
routeData.Values.Add("action", "HttpError500");
break;
default:
routeData.Values.Add("action", "General");
break;
}
Server.ClearError();
}
}
Add the above code in global.asax in application error event block.
You can also refer below link for more details and different methods to implement this
Error Handling in ASP.NET[
^]
Hope this will help you out!!!