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; } 