Create secure application page for sharepoint

Home | SharePoint Development | 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
        {
        get
        {
        SPBasePermissions permissions = base.RightsRequired;
        return permissions;
        }
        }

        protected override void OnPreInit(EventArgs e)
        {

                 base.OnPreInit(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

Leave a Reply