SharePoint 2013匿名访问

时间:2017-02-17 14:47:55

标签: sharepoint-2010 sharepoint-2013 csom

如何使用CSOM添加对列表的匿名访问。在服务器端对象模型中,我可以使用AnonymousPermMask64,但是如何使用CSOM实现它?

1 个答案:

答案 0 :(得分:0)

如果您可以在SharePoint App中使用它,请尝试这样。

string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);

//Get the access token for the URL.  
//Requires this app to be registered with the tenant
string accessToken = TokenHelper.GetAppOnlyAccessToken(
    TokenHelper.SharePointPrincipal, 
    siteUri.Authority, 
    realm).AccessToken;

//Get client context with access token
using(var clientContext = TokenHelper.GetClientContextWithAccessToken(
     siteUri.ToString(),accessToken))
{
    //Do work here
}

参考文献: https://blogs.msdn.microsoft.com/kaevans/2013/10/24/what-every-developer-needs-to-know-about-sharepoint-apps-csom-and-anonymous-publishing-sites/

For Token Helper:https://github.com/OfficeDev/SharePoint-Add-in-CSOM-BasicDataOperations/blob/master/SharePoint-Add-in-CSOM-BasicDataOperationsWeb/TokenHelper.cs