How to catch the 404 error in my web application and provide more useful information?

Platform: ASP.NET| Category: Basic

In the global.asax Application_error Event write the following code

VB.NET


Dim ex As Exception = Server.GetLastError().GetBaseException()
If TypeOf ex Is System.IO.FileNotFoundException Then
	’your code
	’Response.Redirect('err404.aspx')
Else
	’your code
End If

C#


Exception ex = Server.GetLastError().GetBaseException();
if (ex.GetType() == typeof(System.IO.FileNotFoundException)) 
{
	//your code
	Response.Redirect ('err404.aspx');
}
else 
{ 
	//your code
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.