With SharePoint 2010, it has definitely become easier to implement your own custom error page. Using the SPWebApplication.SPCustomPage enumeration, you can set your custom error page to override the default SharePoint one. Actually, you could do the same for your ‘AccessDenied’ or ‘Login’ pages. Here is the full list of out of box pages you could easily override and replace with your own custom ones:
Check out this blog for more information on how you can implement that SharePoint friendly approach.
For our project, we had to use different custom error pages depending on the error status code returned to us. In that case, overriding the default error page would not be enough and a proper alternative solution would probably be to create a custom http module in which you will redirect requests to your custom error page depending on their error status code. On our project, we decided to take a simpler approach which consists of creating an error handler in the Global.asax file that will catch all unhandled errors while processing a request (see here for example), here is how our code looked like:
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
int currentStatusCode = System.Web.HttpContext.Current.Response.StatusCode;
Server.ClearError();
switch (currentStatusCode)
{
case 404: Response.Redirect(ErrorPage404_Url);
break;
case 500: Response.Redirect(ErrorPage500_Url);
break;
default: Response.Redirect(ErrorPage_Url);
break;
}
}
Check out this blog for more information on how you can implement that SharePoint friendly approach.
For our project, we had to use different custom error pages depending on the error status code returned to us. In that case, overriding the default error page would not be enough and a proper alternative solution would probably be to create a custom http module in which you will redirect requests to your custom error page depending on their error status code. On our project, we decided to take a simpler approach which consists of creating an error handler in the Global.asax file that will catch all unhandled errors while processing a request (see here for example), here is how our code looked like:
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
int currentStatusCode = System.Web.HttpContext.Current.Response.StatusCode;
Server.ClearError();
switch (currentStatusCode)
{
case 404: Response.Redirect(ErrorPage404_Url);
break;
case 500: Response.Redirect(ErrorPage500_Url);
break;
default: Response.Redirect(ErrorPage_Url);
break;
}
}