I implemented a custom 500 error page for a SharePoint 2010 publishing website.
The feature receiver of a web application scoped feature sets the custom error page as follows:
var webApplication = properties.Feature.Parent as SPWebApplication;
if (!webApplication.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, _customErrorPage))
{
throw new ApplicationException("Could not set custom error page.");
}
webApplication.Update(true);
In the error page itself, I'd like to log the unhandled exception. However, Context.Server.GetLastError()
always evaluates to null
.
Some research showed that perhaps I should set the redirectMode
attribute of customErrors
in my web.config file to ResponseRewrite
- but that didn't resolve the issue.
ASP.NET developers seem to get around thing by using the Application_Error handler in Global.asax.cs to store the error in order to be able to access it later. We don't have that luxury in SharePoint.
Any suggestions on how to get around this issue?
Thank you