BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Provide User Friendly 404 Pages?

Instead of showing ugly "File Not Found" error message you can handle this error with code in global.asax file. You need to write code in Application_Error event:

[ C# ]

void Application_Error(object sender, EventArgs e)
{
    // Code that runs when an unhandled error occurs
    Exception myEx = Server.GetLastError().GetBaseException();
    if (ex.GetType() == typeof(System.IO.FileNotFoundException))
    {
        // File is not found, so redirect visitor to user friendly 404 page
        Response.Redirect("Default404.aspx");
    }
}

[ VB.NET ]

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when an unhandled error occurs
    Dim myEx As Exception = Server.GetLastError().GetBaseException()
    If TypeOf myEx Is System.IO.FileNotFoundException Then       
        ' File is not found, so redirect visitor to user friendly 404 page
        Response.Redirect("Default404.aspx")
    End If
End Sub



Related articles:


FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.

Related articles: