SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a HttpModule that redirects a user based on values entered in a list on the site. When a user accesses the site and I check for values in the list, it returns empty. When i access the site with the system account, I get the contents of the list just fine.

I tried the following, but the list is still empty:

SPList redirects;
    () => redirects = web.Lists["Redirect"]);

How can I access the list in a way that returns all content, regardless of the permissions of the current user?

share|improve this question
up vote 1 down vote accepted

You need to create your SPWeb/SPSite inside the RunWithElevatedPriveleges block.

The query is run as the identity of the user who originally created the SPSite the SPWeb was derived from even if you execute the query inside a RunWithElevatedPriveleges block.

This is documented here on MSDN SPSecurity.RunWithElevatedPrivileges in the examples section.

You must create a new SPSite object inside the delegate because SPSite objects created outside do not have Full Control even when referenced inside the delegate. Use the using keyword to ensure that the object is disposed in the delegate.

Although the docs refer to SPSite objects the advice also applies to SPWeb objects.

share|improve this answer
Do you know if web.CurrentUser is still set to the correct user or if it changed to represent the System Account when inside the delegate? – cpn Nov 26 '10 at 13:07

Your Answer


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.