Monday, November 05, 2007

How to lock/unlock a site through 'post' method

We can easily lock/unlock a site through API from a console or windows application. By using the properties of SPSite, readlocked or writelocked. But have you tried to do it within a web application. There is a little tricky here.

You will receive error message "The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again" .

ok, then you can do some poke around on google, someone will tell you that should include below code in Page_Load event:

Context.Items[SPGlobalAdmin.RequestFromAdminPort] = true;
Page.RegisterHiddenField("__REQUESTDIGEST", ga.AdminFormDigest);

you also need to define 'ga' in your page cs file:
Microsoft.SharePoint.Administration.SPGlobalAdmin ga = new Microsoft.SharePoint.Administration.SPGlobalAdmin();

But , it still refuse to work!! That makes me crazy!

Finally, if you put your page under C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\ADMIN, a virtual directory under Sharepoint Central Administrator site. It works! The page is code-inline.

by the way, SPGlobalAdmin is obsolete now but I can't find the proper replacement regarding to its AdminformDigest property.

No comments: