Custom Feature and masterpages
- 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?
--
回答
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日 21:55
すべての返信
- 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 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.
--- 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 - 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 .... />
-- - 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 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 .
--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日 21:55
- 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.

