在一个Sharepoint的项目中,需要暂时禁止访问一些网站。因此我做了一webservice完成此功能.代码如下:


[WebMethod]
public bool SuspendSite(string virtualServerUrl, string siteRelativeUrl, bool suspend)
{
 
 Microsoft.SharePoint.Administration.SPGlobalAdmin ga = new Microsoft.SharePoint.Administration.SPGlobalAdmin();
 Microsoft.SharePoint.Administration.SPVirtualServer server = ga.OpenVirtualServer(new Uri(virtualServerUrl));

 if(server == null) return false;

 Microsoft.SharePoint.SPSite spSite = server.Sites[relatedUrl];
 spSite.AllowUnsafeUpdates = true;
    
 spSite.WriteLocked = false;
 spSite.ReadLocked = suspend;
 if(suspend)
 {
  spSite.RootWeb.AllowUnsafeUpdates = true;
  spSite.LockIssue = "Unknown";
 }
 spSite.AllowUnsafeUpdates = false;
 spSite.Close();
 spSite.Dispose();
 return true;
}


要注意几点:
1. 网站必须是顶级网站.
2. 不能从 GetContextSite(Context) 或 new SPSite(url) 得到 SPSite, 必须从SPGlobalAdmin中找出此SPSite,因为此为Global Admin中的功能.否则将有Access Denied的错误.(我也不理解为何要如此,估计是Microsoft的愚蠢吧)
3. WebService的App Pool Account必须有足够的权限.

相关文章:

  • 2021-08-13
  • 2022-01-12
  • 2021-08-28
  • 2021-08-27
  • 2022-12-23
  • 2021-06-07
  • 2021-05-29
猜你喜欢
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2021-10-20
  • 2021-05-31
  • 2021-05-31
相关资源
相似解决方案