Cannot open closed site using CSOM (site policies) RRS feed

  • Question

  • Hi,

    I am trying to open a site from a Web API using CSOM that has been closed / set to read-only through a site policy (which is provisioned through the content type hub). I can call all methods without any issues (including for closing the site), however I cannot open the site after it has been closed due to an "Access denied. You do not have permission to perform this action or access this resource" error:


    using (var ctx = new ClientContext(value.WebUrl))
                        ctx.Credentials = CredentialCache.DefaultNetworkCredentials;
                        var web = ctx.Web;
                        if (value.LockState == "ReadOnly" && web.GetSitePolicyByName(ConfigurationManager.AppSettings["ReadOnlyPolicy"]) != null)
                        else if (value.LockState == "Unlock" && web.HasSitePolicyApplied() && web.IsClosedBySitePolicy())
                    catch (Exception ex)
                        // exception handling

    It seems that with SSOM this functionality should be called under elevated privileges, which makes me wonder...

    Anyone knows what I might be doing wrong?


    • Edited by MZSR Thursday, March 23, 2017 5:49 AM
    Thursday, March 23, 2017 5:47 AM

All replies

  • I forgot to mention I can in fact open a closed site using the GUI (and same user account).
    Thursday, March 23, 2017 12:30 PM
  • Hi,

    Please try to set the credentials below for the ClientContext.

    ctx.Credentials = new NetworkCredential(this.UserName, this.Password, this.Domain);

    Or use system account to check if it works.

    Best Regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Friday, March 24, 2017 9:34 AM
  • Thanks. I had already tried that with an account that has both full control given through a web application policy and site collection administrator permissions, but this did not work either.
    Friday, March 24, 2017 11:19 AM
  • Hi 

    Can you please try to open the site with PnP PowerShell cmdlet and see if it works?

    Set-PnPSiteClosure -State Open

    Try also with credentials with higher privileges.

    Good luck.


    Friday, March 24, 2017 2:12 PM
  • Same issue unfortunately:

    PS C:\TEMP> Set-PnPSiteClosure -State Open
    Set-PnPSiteClosure : Access denied. You do not have permission to perform this action or access this resource.


    Exception occured in scope Microsoft.Office.RecordsManagement.InformationPolicy.ProjectPolicy.OpenProject. Exception=System.UnauthorizedAccessException: Sorry, this site hasn't been shared with you.    
     at Microsoft.Office.RecordsManagement.InformationPolicy.ProjectPolicy.CheckPermissionForCSOM(SPWeb web, ProjectPolicyCSOMPermissionType operationType)    
     at Microsoft.Office.RecordsManagement.InformationPolicy.ProjectPolicy.OpenProject(SPWeb web)    
     at Microsoft.Office.RecordsManagement.InformationPolicy.ProjectPolicyServerStub.InvokeStaticMethod(String methodName, XmlNodeList xmlargs, ProxyContext proxyContext, Boolean& isVoid)    
     at Microsoft.SharePoint.Client.ServerStub.InvokeStaticMethodWithMonitoredScope(String methodName, XmlNodeList args, ProxyContext proxyContext, Boolean& isVoid)

    The same occurs when using the farm account (which has all the permissions including site collection administrator), and when testing on other environments...

    • Edited by MZSR Sunday, March 26, 2017 1:18 PM
    Sunday, March 26, 2017 1:10 PM
  • For Accessing the SP2013 Online side using CSOM server side code, we need to pass the credential of user:

    Thanks, Amit Kumar, LinkedIn Profile ** My Blog

    Friday, April 7, 2017 8:21 AM
  • Is there any update on this?

    Did you find a solution or workaround?

    I can reproduce the same error with CSOM and Powershell PnP.



    Thursday, April 20, 2017 7:05 AM
  • Having exacly the same problem.
    Here's another troubled user:
    (Dennis_J ?)
    Has anyone found a solution?
    Tuesday, July 18, 2017 11:47 AM
  • I am working with SharePoint Online and facing the same issue
    Friday, July 12, 2019 1:37 AM