如何开启匿名访问SharePoint 2010里的Client Object Model

正如大家所知道的,SharePoint 2010 集成了一个新的特性“客户端对象模型( Client Object Model)”,这真的是个很有趣的东西,开发人员可以很方便的写一些简单的程序来访问SharePoint 的数据,无论是.Net 应用程序,Silverlight,还是JavaScript,当然你可能会说我们可以调用SharePoint Web Service,但是对比一下Code,我认为Client Object Model可能来的更容易些。 

言归正传,今天在写一段JavaScript 去访问SharePoint数据的时候,当测试匿名(Anonymous)用户的时候, 弹出了JS 异常:

 

Fiddler 返回的信息:

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Vary: Accept-Encoding

Server: Microsoft-IIS/7.5

SPRequestGuid: 26ba18ca-cab7-453d-b58d-46ab3f4f78f2

X-SharePointHealthScore: 5

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.XXXX

Date: Tue, 04 OCT 2010 06:16:21 GMT

Content-Length: 352

 

[

{

"SchemaVersion":"14.0.0.0","LibraryVersion":"14.0.XXXX.XXXX","ErrorInfo":{

"ErrorMessage":"The method \"GetItems\" of the type \"List\" with id \"{d10206F1-e275-3a1c-b1c2-ea2319a72121}\" is blocked by the administrator on the server.","ErrorValue":null,"ErrorCode":-2147024846,"ErrorTypeName":"Microsoft.SharePoint.Client.ApiBlockedException"

}

}

]

 

后查阅了MSDN, 原来SharePoint 2010 需要修改一个属性SPClientCallableSettings.AnonymousRestrictedTypes为匿名调用GetListItem,为此我们可以使用Feature 或者Powershell去修改这个属性.

 

>>PS

$site = Get-SPWebApplication -Identity "http://MyDev01"

$site.ClientCallableSettings.AnonymousRestrictedTypes.Remove([Microsoft.SharePoint.SPList], "GetItems")

$site.Update()

 

Okay, 现在应该可以了. :)

 

posted @ 2010-11-10 11:51  crazysharepoint  阅读(498)  评论(1编辑  收藏  举报