07 March, 2011

More readable exception messages in Sharepoint 2010

I have the same trouble everytime i upgrade to a newer sharepoint version,
exception messages that doesn't tell me anything.
And everytime i search the net i find a lot of answers that is not working.

So after investigating this, i found the correct way to turn off custom error
message in sharepoint (This means enabling the display of the actual error message).

This picture shows default error meassages in sharepoint, not
very helpful when developing webparts:

Now to enable more useful error messages, which means turning OFF custom error messages:

Navigate and edit the web.config file located here:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config

Change this line:
From:
<customErrors mode="On" />
To:
<customErrors mode="Off" />
Now when an exception occurs in any sharepoint site, it will look like this:

Much better, but if you are developing web parts you might want to turn on the call stack too.
To do this, navigate to the web.config file located under your web site, like:
C:\inetpub\wwwroot\wss\VirtualDirectories\MyTestSite80\web.config

Change callstack in this line:
From:
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
To:
<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">

Now when an exception occurs in any sharepoint site, it will look like this:

So just to clarify:
There is NO need to enable debug in any web.config files (debug=true).
There is NO need to change customerrors mode inside the web.config under the site, this can be left On.
There is NO need to change this file: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\web.config.

No comments:

Post a Comment