0

I am having a problem with a Visual Studio workflow where I am attempting to open the site from an elevated context and am getting an Access Denied exception.

My current user is in the Farm Administrators group, and is also a SCA for the current site. The account that runs the App Pool has also been added to both the Farm Administrators group and the SCA list for the current site.

I am following the typical flow to make sure you are actually using the elevated context, but am getting an Access Denied at the point of opening the Web.

Here is the relevant code:

SPWeb web = SPContext.Current.Web;
SPList lst = web.Lists.TryGetList("Clients");


Guid webId = web.ID;
Guid siteId = web.Site.ID;
Guid listId = lst.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(siteId))
    {
        site.AllowUnsafeUpdates = true;
        using (SPWeb eWeb = site.OpenWeb(webId)) // Error happens here
        {

I am at a loss on this one and have been hitting my head against it for a couple of days. Does anyone have any ideas on where the issue might be happening?

0

try this one

    SPSecurity.RunWithElevatedPrivileges(delegate() 
    {
       using(SPSite site = new SPSite(siteId))
       {
          using(SPWeb web = site.OpenWeb(webId))
          {

              web.AllowUnsafeUpdates = true;
              //code
              web.AllowUnsafeUpdates = false;
          }
       }
    }
1
  • It looks like you are suggesting I use web.AllowUnsafeUpdates to resolve the issue? Unfortunately - the issue happens prior to when that would get set -> the code errors at "SPWeb eWeb = site.OpenWeb(webId)" – Ross Ritchey Mar 31 '17 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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