Configuring anonymous access for site content

With anonymous access configured for the SharePoint web application in the Configuring anonymous access for web applications recipe, anonymous users are now able to access the SharePoint web application. Without granting anonymous users access to the content itself, SharePoint will display the generic Access Denied error page when trying to access the content. In this recipe, we will configure anonymous access for the site content.

How to do it…

Follow these steps to configure anonymous access to the site content:

  1. Navigate to the site collection we are enabling anonymous access for in your preferred web browser.
  2. Click on Site settings from the Settings menu.
  3. Click on Site permissions from the Users and Permissions section as shown in the following screenshot:
    How to do it…
  4. Click on Anonymous Access from the PERMISSIONS tab in the ribbon as shown in the following screenshot:
    How to do it…
  5. Select Entire Web site. Selecting Lists and libraries allows you to specify which content to allow anonymous access to on a more granular level.
    How to do it…
  6. Click on OK.

How it works…

Content in SharePoint is only made available to users who have the appropriate access to the content. Configuring anonymous access at the site level provides anonymous users with appropriate access to the content. Without access to the content, anonymous users would receive the generic SharePoint Access Denied error page.

There's more…

Configuring anonymous access at the site level may also be accomplished with PowerShell or code using the server-side object model.

Configuring anonymous access for site content using PowerShell

Follow these steps to configure anonymous access to site content using PowerShell:

  1. Get the SharePoint site using the Get-SPWeb Cmdlet:
    $web = Get-SPWeb http://sharepoint
    
  2. Set the AnonymousState property to On as follows:
    $web.AnonymousState = [Microsoft.SharePoint.SPWeb.WebAnonymousState]::On
    

    Note

    For the AnonymousState property Disabled is equivalent to Nothing, Enabled is equivalent to Lists and libraries, and On is equivalent to Entire Web site.

  3. Update the SharePoint site using the following command:
    $web.Update()
    

Configuring anonymous access for site content with code using the server-side object model

Follow these steps to configure anonymous access to site content with code using the server-side object model:

  1. Get the SharePoint site collection containing the site in a using statement as follows:
    using (var site = new SPSite("http://sharepoint"))
  2. Open the SharePoint site in a using statement as follows:
    using (var web = site.OpenWeb())
  3. Set the AnonymousState property to On as follows:
    web.AnonymousState = SPWeb.WebAnonymousState.On;
  4. Update the SharePoint site using the following line of code:
    web.Update();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.61.170