Pages

Thursday, August 13, 2015

Allow anonymous access to SharePoint application pages

This post has describe for you how to allow anonymous access to application page without forcing user to provide login credentials.

Setup the Project
1. Open Visual Studio 2013 and Create New Project in “Empty SharePoint Project” and Rename it to “MyFirstAnonymousPageProject”
2. Complete the steps as the usual way when creating a SharePoint project in visual studio 2013.

Add Custom Application Page
1. Right click on the project name “MyFirstAnonymousPageProject” > Add > SharePoint “Layouts” Mapped Folder. This will automatically create a folder with the name of your project under Layout folder.
2. Right click on the folder >Add > New Item > Application Page.
3. Name the page “AnonymousPage.aspx”

Setup anonymous access
1. Go to the code behind part of “AnonymousPage.aspx” page
2. You can see that by default, the page is inherited from “LayoutsPageBase”. Change the inheritance by replacing “LayoutsPageBase” to “UnsecuredLayoutsPageBase”.
Ex: – public partial class AnonymousPage : UnsecuredLayoutsPageBase
3. Next override “AllowAnonymousAccess ” method of the UnsecuredLayoutsPageBase, to allow anonymous access. Set “return true” of the “Get” property.
Ex: -
public partial class AnonymousAccess : UnsecuredLayoutsPageBase
{
    protected override bool AllowAnonymousAccess
    {
        get
        {
            return true;
        }
    }

}

Ready the solution
1. Deploy the solution by right clicking on your project name.
2. Browse the page by navigation to your solution URL once the deployment completed.

No comments:

Post a Comment