Create unsecure application pages for sharepoint

There are times, where we need to create an application page to be accessed anonymously by the user, instead of the user signing-in and accessing the page. Here is the code-snippet to create an unsecure application page for sharepoint.

    public partial class UnsecureApplicationPage : Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase
    // inherit the page from Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase instead of Microsoft.SharePoint.WebControls.LayoutsPageBase    

    {

        protected void Page_Load(object sender, EventArgs e)
        {                   

        }       

    //override the allow anonymous property to true
        protected override bool AllowAnonymousAccess
        {
            get { return true; }
        }

        protected override bool AllowNullWeb { get { return true; } }

        protected override void OnPreInit(EventArgs e)
        {

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                base.OnPreInit(e);
                Microsoft.SharePoint.SPWeb _Web = SPControl.GetContextWeb(Context);
                this.MasterPageFile = _Web.MasterUrl;
            });

        }

    }

 Subscribe to my post

One thought on “Create unsecure application pages for sharepoint

  1. Pingback: Create unsecure application pages for sharepoint - My experiments with SharePoint, Azure and .NET using Visual Studio

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.