Subscribe: SharePoint SharePoint SharePoint
Showing posts with label ecmascript run with elevated privileges. Show all posts
Showing posts with label ecmascript run with elevated privileges. Show all posts

Saturday, February 1, 2014

Running ECMAScript under Anonymous access

Client Object Model in SharePoint has been quite significant since its introduction in SharePoint 2010. It does allow us to rapidly build web parts in JSOM/ECMA  with little or no need for compiled code.

The functionality is quite simple and involves creating some functions and executing them asynchronously. This behavior prevents our browser from freezing until the response has come back from the server.

Now we need to take care of some important things while creating web parts using ECMAScript. Since the pages would be accessed  by visitors and may also be accessed by anonymous users, so site admins need to take care of the proper permissions.

Anonymous users , by default,  do not have the privilege of requesting the server for resources even for read only access. One of the example may be like if there is a picture library in the site and a carousel web part on the home page is displaying those pictures . In such cases, while accessing the home page, the anonymous users will get the following error:


It occurs because anonymous users are restricted on requesting the server for "GetItems" property of the list. This behavior is default for anonymous users.


So in order to prevent this error, the site admin must execute the following script in powershell:
 $webapp = Get-SPWebApplication “http://somesite/”
 $webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], "GetItems") 
 $webapp.Update()

Before doing this make sure "Anonymous Access" is allowed in Web Application: