Skip to main content
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackSharePoint/status/878304465597587456
added 61 characters in body
Source Link
Ola
  • 4.4k
  • 27
  • 135
  • 233

I created a custom action. This custom action is referencing to an application page. This application page is anonymous accessable. On this application page I have a button. When you click on this button the site collection needs to change to readonly.

I tried many solutions but I still got an access denied pagethis access denied page. See below all solutions I tried:

Solution 1:

SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite([Site GUID here]) { site.ReadOnly = true; } } 

Solution 2:

 SPSite site = new SPSite("mysitecollectionurl.com"); { site.ReadOnly = true; //Set lock comments site.LockIssue = "Maintenance"; } 

Solution 3:

SPSite site = new SPSite([Site GUID here], SPUserToken.SystemAccount) { site.ReadOnly = true; } 

Solution 4:

private void LockSiteCollection(SPSite Site) { //Try lock the Portal Site Collection try { Site.LockIssue = "Your Lock reason"; } //handle prior left out read only locks due to errors. catch (UnauthorizedAccessException) { Site.ReadOnly = false; Site.LockIssue = "Your Lock reason"; } Site.ReadOnly = true; } 

I created a custom action. This custom action is referencing to an application page. This application page is anonymous accessable. On this application page I have a button. When you click on this button the site collection needs to change to readonly.

I tried many solutions but I still got an access denied page. See below all solutions I tried:

Solution 1:

SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite([Site GUID here]) { site.ReadOnly = true; } } 

Solution 2:

 SPSite site = new SPSite("mysitecollectionurl.com"); { site.ReadOnly = true; //Set lock comments site.LockIssue = "Maintenance"; } 

Solution 3:

SPSite site = new SPSite([Site GUID here], SPUserToken.SystemAccount) { site.ReadOnly = true; } 

Solution 4:

private void LockSiteCollection(SPSite Site) { //Try lock the Portal Site Collection try { Site.LockIssue = "Your Lock reason"; } //handle prior left out read only locks due to errors. catch (UnauthorizedAccessException) { Site.ReadOnly = false; Site.LockIssue = "Your Lock reason"; } Site.ReadOnly = true; } 

I created a custom action. This custom action is referencing to an application page. This application page is anonymous accessable. On this application page I have a button. When you click on this button the site collection needs to change to readonly.

I tried many solutions but I still got this access denied page. See below all solutions I tried:

Solution 1:

SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite([Site GUID here]) { site.ReadOnly = true; } } 

Solution 2:

 SPSite site = new SPSite("mysitecollectionurl.com"); { site.ReadOnly = true; //Set lock comments site.LockIssue = "Maintenance"; } 

Solution 3:

SPSite site = new SPSite([Site GUID here], SPUserToken.SystemAccount) { site.ReadOnly = true; } 

Solution 4:

private void LockSiteCollection(SPSite Site) { //Try lock the Portal Site Collection try { Site.LockIssue = "Your Lock reason"; } //handle prior left out read only locks due to errors. catch (UnauthorizedAccessException) { Site.ReadOnly = false; Site.LockIssue = "Your Lock reason"; } Site.ReadOnly = true; } 
Source Link
Ola
  • 4.4k
  • 27
  • 135
  • 233

How to set site collection readonly programmatically?

I created a custom action. This custom action is referencing to an application page. This application page is anonymous accessable. On this application page I have a button. When you click on this button the site collection needs to change to readonly.

I tried many solutions but I still got an access denied page. See below all solutions I tried:

Solution 1:

SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite([Site GUID here]) { site.ReadOnly = true; } } 

Solution 2:

 SPSite site = new SPSite("mysitecollectionurl.com"); { site.ReadOnly = true; //Set lock comments site.LockIssue = "Maintenance"; } 

Solution 3:

SPSite site = new SPSite([Site GUID here], SPUserToken.SystemAccount) { site.ReadOnly = true; } 

Solution 4:

private void LockSiteCollection(SPSite Site) { //Try lock the Portal Site Collection try { Site.LockIssue = "Your Lock reason"; } //handle prior left out read only locks due to errors. catch (UnauthorizedAccessException) { Site.ReadOnly = false; Site.LockIssue = "Your Lock reason"; } Site.ReadOnly = true; }