Question

J'ai conçu un module qui modifie la page principale dinamiquement basée sur les privilèges de connexion utilisateur.

J'ai suivi ce tutoriel:

http://Ranaictiu-TechnicalBlog.Blogspot.it/2009/10/SharePoint-Dynamiquement-change-Master.html?showComment=1354630820782#C5132604142640789136

Tout fonctionne bien.Mais ne fonctionne que sur la page d'accueil SharePoint.Si vous essayez d'aller à une autre page comme

_Layouts / utilisateur.aspx

ou

/ _ mises en page / closeconnection.aspx

Alors la page se bloque!

public class DynamicMasterPageModule : IHttpModule
{
    public void Dispose()
    {


    }


    public void Init(HttpApplication context)
    {
        context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
    }


    void context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        Page page = HttpContext.Current.CurrentHandler as Page;
        if (page != null)
        {
            page.PreInit += new EventHandler(page_PreInit);
        }
    }
void page_PreInit(object sender, EventArgs e)
    {
        Page page = sender as Page;
        string pageNo = ConfigurationManager.AppSettings["MasterPageNo"];




        if (page != null)
        {
            if (pageNo.Equals("1"))
            {
                page.MasterPageFile = "~masterurl/custom.master";
                if (SPContext.Current != null)
                {
                    SPContext.Current.Web.CustomMasterUrl = "/_catalogs/masterpage/custom1.master";
                }
            }
            else if (pageNo.Equals("2"))
            {
                page.MasterPageFile = "~masterurl/custom.master";
                if (SPContext.Current != null)
                {
                    SPContext.Current.Web.CustomMasterUrl = "/_catalogs/masterpage/custom2.master";
                }


            }
            else
            {
                page.MasterPageFile = "~masterurl/default.master";
                if (SPContext.Current != null)
                {
                    SPContext.Current.Web.MasterUrl = "/_catalogs/masterpage/default.master";
                }
            }


        }

ERREUR:

The file '/_layouts/masterurl/custom.master' does not exist. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The file '/_layouts/masterurl/custom.master' does not exist.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[HttpException (0x80004005): The file '/_layouts/masterurl/custom.master' does not exist.]
   System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) +11108402
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +163
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +116
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +175
   System.Web.UI.Page.get_Master() +69
   System.Web.UI.Page.ApplyMasterPage() +18
   System.Web.UI.Page.PerformPreInit() +58
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1256

Était-ce utile?

La solution

Dans Suivi de mon commentaire, le code est en effet recherché comme s'il ne fait probablement pas référence à la page maître correctement.

Le code devrait ressembler davantage à ceci:

string masterUrl = site.ServerRelativeUrl;

if (!masterUrl.EndsWith(@"/"))
{
    masterUrl = masterUrl + @"/";
}

SPFile file = web.GetFile(masterUrl + "_catalogs/masterpage/custom.master");

Cela donnera à l'URL relative basée sur l'autorisation correcte pour la page maître.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top