Create secure application page for sharepoint

Creating an application page for sharepoint is fairly simple and straight-forward. To make that application page secure, just do some extra steps in the code. Here is the code-snippet for creating secure application page in sharepoint .

public partial class SampleSecurePage : Microsoft.SharePoint.WebControls.LayoutsPageBase    


        public SampleSecurePage()
           //In the constructor define rights check mode to be done on the pre-init event  
            this.RightsCheckMode = RightsCheckModes.OnPreInit;


        //get the permission set from spbase permission enumeration
        protected override SPBasePermissions RightsRequired
        SPBasePermissions permissions = base.RightsRequired;
        return permissions;

        protected override void OnPreInit(EventArgs e)

                 Microsoft.SharePoint.SPWeb _Web = SPControl.GetContextWeb(Context);

        //dynamically assign the master of the current spweb to the application page
                 this.MasterPageFile = _Web.MasterUrl;

             if (!HttpContext.Current.User.Identity.IsAuthenticated)
                    //re-direct the user to log-in page and authenticate



        protected void Page_Load(object sender, EventArgs e)
            //do some logic here             



 Subscribe to my post

One thought on “Create secure application page for sharepoint

  1. Pingback: Create secure application page 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: Logo

You are commenting using your 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.