Wednesday, October 29, 2008

Redirecting to Custom Error Page When 404 Page not Found Occurs.

Write the below code in global.asax file in Application_Error Method.
StringBuilder errMessage = new StringBuilder();
Exception ex = Server.GetLastError();
if (ex is HttpException)
{
HttpException checkException = (HttpException)ex;

switch (checkException.GetHttpCode())
{
case 403:
{
errMessage.Append("You are not allowed to view that page.");
break;
}
case 404:
{
errMessage.Append("The page you requested cannot be found.");
break;
}
}
}

we can number of http code here.

No comments: