How can we provide User Friendly 404 Pages if we do not find page?

 Posted by Vishalneeraj-24503 on 3/1/2015 | Category: ASP.NET Interview questions | Views: 1273 | Points: 40
Answer:

Instead of showing File Not Found error message we can handle this error with code in global.asax file. We need to write code in Application_Error event as:-

void Application_Error(object sender,EventArgs e) 

{
//Code that runs when an unhandled error occurs
Exception Ex = Server.GetLastError().GetBaseException();
if (ex.GetType() == typeof(System.IO.FileNotFoundException))
{
Response.Redirect("Default404.aspx");
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response