0

I have an internal portal/sharepoint site with a custom webpart used to serve up Crystal Reports reports. Currently I need to give Buitlin/Users Site Auditor permission in "User Policy" for the web application or they get an access denied error. I think it is something to do with a RunWithElevatedPrivileges command that is not correct. Also Site admins have no problems opening the reports.

 SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            AddSites(SPWebApplication.Lookup(uri).Sites[0].AllWebs));

        if (!string.IsNullOrEmpty(webpart.Department))
        {
            reportsSiteList.SelectedValue = webpart.Department;

does this look correct? if so, any ideas about the access denied errors?

1 Answer 1

0

You should also use the site context with in the elevated privileges code. code sample below:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    //New SPSite object.
     using (SPSite site = new SPSite(web.Site.ID))
     {
    //Do things by assuming the permission of the "system account".
     }
});

Additionally, verify what is the service account used for the app pool used in the current web applications. generally, elevated priviliges code runs with the context of app pool account and that account should have full priviliges.

4
  • would that go before or after the "AddSites" line? or is that instead of?
    – James5060
    Commented Mar 29, 2016 at 19:33
  • service account for the AppPool is NetworkService
    – James5060
    Commented Mar 29, 2016 at 19:45
  • the code will be before the add sites and its not recommended to use the network service as a app pool account. refer microsoft msdn/technet articles on the sharepoint farm configuration.
    – kesava
    Commented Mar 29, 2016 at 20:23
  • I think I added the code correctly, if I use anything other than "NetworkService" the whole site is inaccessible, I have other sites on the IIS server and the app pools use a service account that I set up, when I try to use that for the sharepoint site I have "issues"
    – James5060
    Commented Mar 29, 2016 at 21:11

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.