0
votes

Hi When i try to activate my branding feature i am getting 403 error .I am deploying my css script files into layouts folder .

I am not able to understand where i was wrong it is working in all the test environments but not in production .

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        // Get the SPWeb we're being activated in.
        var web = (SPWeb)properties.Feature.Parent;

        if (null != web)
        {

            // Get the Site Collection root path to get the master page gallery.
            string siteCollectionRoot = web.Site.RootWeb.Url;

            // Set the Site Master to Custom.master
            var siteMaster = new Uri(siteCollectionRoot +
                                     "/_catalogs/masterpage/" +
                                     "MYCUSTOM.Master");
            web.CustomMasterUrl = siteMaster.AbsolutePath;

            // Set the System Master to Custom.master
            var systemMaster = new Uri(siteCollectionRoot +
                                       "/_catalogs/masterpage/" +
                                       "MYCUSTOM.Master");
            web.MasterUrl = systemMaster.AbsolutePath;

            // Clear the Alternate CSS
            web.AlternateCssUrl = string.Empty;


            // Save the changes back to the web
            web.Update();



        }
    }
1

1 Answers

1
votes

It could be a few things, I would start with allow unsafe updates and then move on to elevating privileges as normally in dev environments you have full access. The code snippets incorporates the allow unsafe updates.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        // Get the SPWeb we're being activated in.
        var web = (SPWeb)properties.Feature.Parent;
        web.AllowUnsafeUpdates = true;
        if (null != web)
        {

            // Get the Site Collection root path to get the master page gallery.
            string siteCollectionRoot = web.Site.RootWeb.Url;

            // Set the Site Master to Custom.master
            var siteMaster = new Uri(siteCollectionRoot +
                                     "/_catalogs/masterpage/" +
                                     "MYCUSTOM.Master");
            web.CustomMasterUrl = siteMaster.AbsolutePath;

            // Set the System Master to Custom.master
            var systemMaster = new Uri(siteCollectionRoot +
                                       "/_catalogs/masterpage/" +
                                       "MYCUSTOM.Master");
            web.MasterUrl = systemMaster.AbsolutePath;

            // Clear the Alternate CSS
            web.AlternateCssUrl = string.Empty;


            // Save the changes back to the web
            web.Update();
           web.AllowUnsafeUpdates = false;


        }
    }