403错误SharePoint自定义功能激活

时间:2015-10-26 00:23:59

标签: sharepoint sharepoint-2013

嗨当我尝试激活我的品牌特征时,我收到403错误。我正在将我的css脚本文件部署到layouts文件夹中。

我无法理解我在哪里错了它在所有测试环境中工作但不在生产中。

 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 个答案:

答案 0 :(得分:1)

这可能是一些事情,我会从允许不安全的更新开始,然后继续升级权限,就像通常在您拥有完全访问权限的开发环境中一样。代码片段包含允许不安全的更新。

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;


        }
    }