MSDN > 論壇首頁 > SharePoint - Development and Programming > Custom Feature and masterpages
發問發問
 

已答覆Custom Feature and masterpages

  • 2009年7月4日 上午 08:30zdragon 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    HI.
    I've developed a feature (deployed with scope Web ) which has custom pages too.
    I had deployed it to a server which has multiple site collections
    each site collection will have its own look and feel + different masterpages.
    My biggest problem is that I need my feature pages to have the same look and feel as  site were it is deployed.
    is there any SPTag that I can use to load masterpages specified for the site? or I have to do it programmaticaly?
    --

解答

  • 2009年7月5日 下午 03:33Dave Hunter 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    Hi,

    To make application pages (pages which exist in the _layouts directory) to use a different masterpage or to customise the application.master, you have two options

    1. Modify the _layouts in a supported manner, please see http://support.microsoft.com/kb/944105.  It involves either backing up the _layouts and modifying the masterpage or creating a copy of the _layouts and changing the virtual directory to use the new folder (my preferred solution).
    2. Create a httpmodule which replaces the application.master with your custom one, please see http://graegert.com/?p=781

    I prefer the HttpModule, but I am a developer, if you don't have Visual Studio then use option 1.

    Hope this helps

    Dave 


    My SharePoint Blog - http://www.davehunter.co.uk/blog
    • 已標示為解答zdragon 2009年7月5日 下午 09:55
    •  

所有回覆

  • 2009年7月4日 下午 04:16Sébastien Sougnez 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    Hello,

    Maybe I didn't understand your probleme, but normally, in your ASPX page, you have something like this :

    <%@ Page Language="C#" Inherits="PageApp1.PageApp1" MasterPageFile="~/_layouts/application.master" EnableViewState="false" EnableViewStateMac="false" %> 
    

    So you juste have to change the MasterpageFile attribute, haven't you ?



    http://www.areaprog.com
  • 2009年7月5日 上午 09:10zdragon 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    MasterPageFile="~/_layouts/application.master" 

    replacig this bit will work only for 1 individual site collection.

    the feature have to be enabled in other site collections too and those othere sites wil have their own masterpage..

    ex. Site Coll 1. will have SiteOne.master

    Collection 2: SiteTwo.master.

    The problem now is that my feature aspx pages have to pick up one of those master pages. depending in what site collection is loaded.

     


    --
  • 2009年7月5日 上午 09:39Sébastien Sougnez 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼
    Hello,

    have you a way to retrieve the name of the masterpage to attach to the page ? If yes, you can change the master page of the page in PreInit event :

    void Page_PreInit(Object sender, EventArgs e)
    {
    this.MasterPageFile = "~/NewMaster.master";
    }

    I said that, but I don't know if your issue is to retrieve the name of the master page or to change the page dynamically :-)
    http://www.areaprog.com
  • 2009年7月5日 上午 09:47zdragon 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi!
    I do consider this sollution too.
    there is an elegant way to do it with SPWeb.MAsterUrl property
     http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.masterurl.aspx

      is  there another way to do it? for example with an HTML tag ?
    ex, <SPMasterPage .... />

    --
  • 2009年7月5日 上午 09:51Sébastien Sougnez 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hello,

    I don't think that you can. I searched on web and I found this link : http://www.odetocode.com/articles/450.aspx. Nothing in this article speaks about changing page dynamicaly by the ASPX code...
    http://www.areaprog.com
  • 2009年7月5日 上午 10:26zdragon 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hello,

    I don't think that you can. I searched on web and I found this link : http://www.odetocode.com/articles/450.aspx. Nothing in this article speaks about changing page dynamicaly by the ASPX code...
    http://www.areaprog.com


    in the link above it says : The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.

    so it is possible to do it .


    --
  • 2009年7月5日 下午 03:33Dave Hunter 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    Hi,

    To make application pages (pages which exist in the _layouts directory) to use a different masterpage or to customise the application.master, you have two options

    1. Modify the _layouts in a supported manner, please see http://support.microsoft.com/kb/944105.  It involves either backing up the _layouts and modifying the masterpage or creating a copy of the _layouts and changing the virtual directory to use the new folder (my preferred solution).
    2. Create a httpmodule which replaces the application.master with your custom one, please see http://graegert.com/?p=781

    I prefer the HttpModule, but I am a developer, if you don't have Visual Studio then use option 1.

    Hope this helps

    Dave 


    My SharePoint Blog - http://www.davehunter.co.uk/blog
    • 已標示為解答zdragon 2009年7月5日 下午 09:55
    •  
  • 2009年7月6日 上午 11:21kesav7902 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    hello,

    u can create a page using the publishing page object in the object model (creating the page dynamically in a publishing site)there by u can assigne the master page to it on the fly as a part of the feature reciever code --> acheiveing the same look and feel across the site collection where ever u wish to have ....

    cheers,
    keshav.