Catching 404 Error in WebApplication


The code snippet explaind how to handle the 404 (FileNotFoundException) in webApplication and to provide useful information.

The code snippet explaind how to handle the 404 (FileNotFoundException) in webApplication and to provide useful information.

In the global.asax Application_error Event write the following


C#.NET code :



void Application_Error(object sender, EventArgs e)
{
Exception e1 = Server.GetLastError().GetBaseException();
if (e1.GetType() == typeof(System.IO.FileNotFoundException))
{
Response.Redirect("ex.html");

}
}




VB.NET Code:


void Application_Error(object sender, EventArgs e)
{

Dim ex As Exception=Server.GetLastError().GetBaseException();

If TypeOf ex Is System.IO.FileNotFoundException Then

Response.Redirect("ex.html");

else

//Code

End If
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: