SharePoint Sharpener

Obsessively Sharpening SharePoint

Posts Tagged ‘web part

Inserting a SharePoint Web Part Generates an Internal Server Error (500)

leave a comment »

One of my clients recently reported some strange behaviour by their SharePoint 2007 publishing site.

Inserting a web part would sometimes generate an internal server error (status code 500). You’ll notice the word “sometimes” which really isn’t something you want to hear when trying to diagnose SharePoint problems 🙂

Anyway, it turned out that the described behaviour is entirely reproducible as it is only in certain web part zones that the problem occurs – but it will always happen in those particular zones if a web part is attempted to be inserted.

So, what is the pattern? Have a look at the highlighted part of this screenshot:

Screenshot: 500 Internal server error

The screenshot is in fact the Insert Web Part pop-up window. The key to solving the problem is in the ZoneDisplayName part of the querystring. It contains an escaped extended character, in this case the Danish letter “ø”, because the name of the zone is “Højre kolonne” (Right column).

The error does not occur when a web part is inserted into a zone with a name that doesn’t contain extended characters, such as “Venstre kolonne” (Left column).

The solution

Realising the SharePoint server lives behind an ISA Server I knew where to look first. The easiest way to bypass the ISA is to log into the SharePoint server with Remote Desktop, fire up a browser and try to insert a web part in the same zone. So that’s what I did.

Boom. No problems, the web part could be inserted.

The good news is that the problem can be alleviated by making a few changes to the ISA configuration. See this KB for more info:


Written by Thomas Sondergaard

March 30, 2011 at 2:12 pm

Elevation: Run Code as an Administrator

with one comment

Sometimes you may need your web part to perform tasks for which the current user doesn’t have priviliges. For instance, we needed a sign up form for our WCM web site where the user could enter contact information that should be stored in a list.

Naturally, our web site runs with anonymous access and the the anonymous users do not have access to the underlying lists, including the list where the contact information goes.

Thus, submitting to the list is not just a matter of doing an Items.Add() because this causes a login dialogue to pop up and ultimately a 401 Unauthorized error.

Normally you’d create an element in the list with code similar to this:



However, if the logged-in user doesn’t have sufficient credentials to write to the list, a login dialogue will pop up.


Run with Elevation

To get around this problem you can use SPSecurity.RunWithElevatedPriviliges() like this:



For this to work, you need to instantiate the SPSite and SPWeb objects inside delegate():



Now the list will be updated with a new element, created by the system account.

Written by Thomas Sondergaard

August 27, 2008 at 6:56 am