Friday, November 19, 2010

How to make an _layouts page (application page) in SharePoint anonymous?

Scenario:
How to make an _layouts page (application page) in SharePoint anonymous?

Explanation:
The application pages (custom pages that are created inside the layouts folder) in SharePoint  will ask for authentication even when a user tries to access them from a site that is configured for anonymous access (public facing site).

Resolution:

  • Make sure that the application page is inherited from "Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase"
  • Override the AllowAnonymousAccess property and return true
If the application page does not have code-behind, the below snippet will mark the property "AllowAnonymousAccess" to true:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" DynamicMasterPageFile="~masterurl/default.master" %>
<script runat="server" type="text/C#">
protected override bool AllowAnonymousAccess
{  
    get
    {  
        return true;  
    }  
}
</script>

If the application page has code-behind, the below snippet will mark the property "AllowAnonymousAccess" to true:

public class ApplicationPage :  Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase
{
  protected override bool AllowAnonymousAccess { get { return true; }
}

No comments:

Post a Comment