Automatically enabling anonymous authentication on SharePoint 2010 site

When building public site using SharePoint 2010 one of the items on the list is to make the site accessible to anonymous user – obviously.

There are few things involved having this happen.

First setting must be performed on Web Application level.

1. Navigate to Central Administration

2. Click On Application Management -> Authentication Providers.

3. Select the web application you want to make anonymous from the drop down of web applications.

4. Click on the Default zone.

5. Check the box next to anonymous access; click OK.

Now that’s not just it. Now we need to enable anonymous access on the root web of our site collection or on all of the site collections if you have more than one.

The easiest way to achieve that if you’re deploying the site using a automatic provisioning tool is to create a feature which will have a feature receiver attached to it. The feature receiver will set anonymous set of permissions on the root web of the site collection.

The site template would activate this feature on the web site collection level.

Here is the code of the feature receiver:

using (SPSite site = (SPSite)properties.Feature.Parent)
{
using (site.RootWeb)
{
site.RootWeb.AnonymousPermMask64 =
SPBasePermissions.BrowseDirectories |
SPBasePermissions.BrowseUserInfo | SPBasePermissions.Open |
SPBasePermissions.OpenItems | SPBasePermissions.ViewFormPages |
SPBasePermissions.ViewListItems | SPBasePermissions.ViewPages |
SPBasePermissions.ViewVersions;
site.RootWeb.AnonymousState = SPWeb.WebAnonymousState.On;
}
}
Ensure the list of permissions given in AnonymousPermMask reflects permissions you actually want to give to a user.
Good luck!
This entry was posted in sharepoint, sharepoint 2010 and tagged , , . Bookmark the permalink.

Comments are closed.