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
}
