Friday, July 11, 2008

Sharepoint Web Part Causing Authentication Prompt

I just spent god-knows how long tracking down a simple issue with a Sharepoint web part. Basically a simple web part was causing the authentication box to pop up for anonymous users. The web part was doing a query of sub-webs to compile a list. Because it was using the Sharepoint object model, it required higher privileges than the anonymous user.

Following this article, it was easy enough to raise the privileges for the chunk of code that required it. The main problem though was a small call to SPContext.Current that I didn't spot.

Simply removing this, and instead passing in the ID of the current site to the elevated method solved the problem. I'll know for next time...