I got Error message “value does not fall within the expected range” in QA. It is working fine in DEV. I had increased threshold value from 12 to 20 in QA and working fine. but client does not approved to increase same in prod.

I have also reverted lookup threshold value back to 12 and add my id in user policy again it worked. but as we could not add normal user to user policy this will not work again in prod. Then I tried to use run with elevated privileged, it worked fine now in QA but does not worked in prod. what change i need to do in code.

How can I pass app pool account. I am using below, please correct me where I am going wrong.

SPUserToken token = oWeb.AllUsers[@"domain\abc-18"].UserToken;
 using (SPSite elevatedSite = new SPSite(oWeb.Site.ID, token))
                    SPWeb web = elevatedSite.OpenWeb();

I am getting user could not be found.


2 Answers 2


Web.AllUsers Does not cover all the users so you have to check your user in web.Users as well in web.SiteUsers.

SPUserCollection users = web.Users ; SPWeb.Users gets the collection of user objects that are explicitly assigned permissions in the Web site . It will not return users who have access through a group.

SPUserCollection users = web.AllUsers ; SPWeb.AllUsers gets the collection of user objects that represents all users who are either members of the site collection or who have browsed to the site as authenticated members of a domain group in the site. (note the "browsed to" here... adding a AD group to a site does not add the users to AllUsers immediately... they will not be listed here until they have visited the site at least once.)

SPUserCollection users = web.SiteUsers ; SPWeb.SiteUsers gets the collection of all users that belong to the site collection.


If you want to run your code using app pool account, then why don't you try using "SPSecurity.RunWithElevatedPrivileges" method

    using (SPSite site = new SPSite(web.Site.ID))
    // implementation details omitted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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