在 WSS 3.0 中自定义 default.master
有谁知道如何为 WSS 3.0 站点自定义母版页(即 default.master)? 实际上,我已经知道如何自定义母版页(即通过 SharePoint Designer 或文本编辑器),我更感兴趣的是学习如何告诉 WSS 3.0 使用我的自定义母版页。
我已使用自定义版本重命名了default.master,并且该版本有效,但这为所有 WSS 站点设置了它。 我希望能够为网站集 A 使用母版页的版本 A,并为其他网站集使用单独的母版页。
请注意,我不是指 MOSS 2007。我已经知道如何设置 MOSS 2007 的母版页。不过,我似乎不知道如何为 WSS 3.0 执行此操作。
谢谢。
Does anyone know how to customize the master page (i.e. default.master) for a WSS 3.0 site? Actually, I already know how to customize the master page (i.e. via SharePoint Designer, or a text editor), I'm more interested in learning how to tell WSS 3.0 to use my customized master page.
I've renamed the default.master with my customized version and that works, but that sets it for all WSS sites. I want to be able to use version A of a master page for site collection A, and a separate master page for other site collections.
Note, I'm NOT referring to MOSS 2007. I already know how to set the master page for MOSS 2007. I can't seem to figure out how to do it for WSS 3.0 though.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WSS 页面像常规 Web 应用程序一样使用母版页。 但是,如果 MasterPageFile 属性是令牌,则该值设置为“~default.master”。 该标记将替换为页面 PreInit 方法中对母版页的实际引用。
您可以将 ~default.master 的值更改为您喜欢的任何值。 但更好的解决方案是执行与 SharePoint 相同类型的操作。
我向我的 SharePoint 网站添加了 HttpHandler。 该处理程序附加到 PreRequestHandlerExecute 方法,并在 SharePoint 开始呈现页面之前更改母版页文件属性的值。
在 web.config 的 httpModules 部分添加一行,如下所示:
然后创建一个像这样的类:
namespace MyClassLibrary.Utility
{
公共类 MasterPageHttpModule :IHttpModule
{
公共无效初始化(HttpApplication上下文)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
现在
。
您正在动态选择一个母版页面
WSS pages use Master Pages just like regular web apps. However, the value if the MasterPageFile attribute is a token, and is set to "~default.master". This token gets replaced with the actual reference to the master page in the page's PreInit method.
You can change the value of ~default.master to anything you like. But a better solution is to do the same type of thing that SharePoint does.
I added an HttpHandler to my SharePoint site. The handler attaches to the PreRequestHandlerExecute method, and changes the value of the master page file attribute before SharePoint starts rendering the page.
Add a line to the httpModules section of the web.config that looks like this:
Then create a class like this:
namespace MyClassLibrary.Utility
{
public class MasterPageHttpModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
}
Now you are dynamically choosing a mater page.
您需要更改表示站点的 SPWeb 对象上的 MasterUrl 属性。 执行此操作的一个好方法是创建一个 SharePoint 功能,该功能在激活时设置属性,在停用时恢复原始值。 Feature.xml 可能如下所示:
Masterpage.xml 文件将您的母版页上传到库:
将此功能与包含 MyFeatureReceiver 类的 MyAssembly.dll 一起包含在 WSP 解决方案中,如下所示:
最后,部署解决方案并激活您网站上的功能。
You need to change the MasterUrl property on the SPWeb object representing the site. A good way to do this is to create a SharePoint feature that when activated sets the property, and when deactivated restores the original value. The Feature.xml could look like this:
The file Masterpage.xml uploads your master page to the gallery:
Include this feature in a WSP solution along with the MyAssembly.dll containing the MyFeatureReceiver class, which goes like this:
Finally, deploy the solution and activate the feature on your site(s).