Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

If you have .NET reflector, check out the way SharePoint handles this stuff with its own error page.

Specifically, look at SPUtility.TransferToErrorPage in the Microsoft.SharePoint.dll, and the Microsoft.SharePoint.ApplicationPages.ErrorPage code behind class in the Microsoft.SharePoint.ApplicationPages.dll

You'll see that SharePoint actually clears the error from HttpContext.Server, and storing the error info in the HttpContext.Items collection before doing a server.transfer.

eg the error text is stored in context.Items["ErrorText"]

share|improve this answer
    
Paul, thanks for the tip. The ErrorText in the context always appears to be "An unexpected error has occurred", not the true underlying exception message. –  George Durzi Nov 29 '11 at 3:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.