We are trying to make a site read-only from the code-behind of an application page.
When executing the code-snippet from a timer job or a console application it works perfectly, but it throws an
Access Denied
when run from the code-behind of the application page.
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite([Site GUID here])
{
site.ReadOnly = true;
}
}
We have tried reflecting what SharePoint does on the application page in Central Admin, but it was not clear why it works there and not on our page (Some internal methods gets the parameter RequireCentralAdmin
though, what ever that means)
Any clues?