Wednesday, May 8, 2013

Granting Anonymous Access to Sharepoint List / Library Programmatically


In this post, we will see how to enable and disable Anonymous access to a List or Document library from a Sharepoint feature (C# code).

There are 3 different steps involved in granting Anonymous access to a List/Library in a right way.

STEP1:

Enabling the anonymous access to the Web application from Central Admin. This does not mean that the whole web application is now anonymous. This step signifies that this web application has the ability to host resources that can be accessed by Anonymous user.

Then,

Then,

Now click save and close Central Admin. I am pointing again that the above step will not make the whole web application accessible to anonymous users. This will create scope for hosting something that can be accessible by anonymous user.

STEP2:

Enabling the Anonymous permissions in Web application settings. Go to Site Permission screen. As you have already enabled Anonymous access for this web application from central admin, a new button "Anonymous Access" will appear on the ribbon.


Now, the list can be accessed by unauthenticated / anonymous users.

But, in real time scenarios, step 3 is not recommended as it involves manual intervention in granting access, which is not possible in most of the PRODUCTION scenarios.

So, it is recommended to perform step 3 using a feature activation or de-activation.

Here is the code for making a Document library anonymous while activating a feature.


Here is the code for removing Anonymous access to a Document library while de-activating a feature.

Happy coding!










No comments:

Post a Comment