简体   繁体   English

ASP.NET/SharePoint母版页问题

[英]ASP.NET/SharePoint master page issue

I am using SharePoint Server 2007 + C# + .Net 3.5 + VSTS 2008 + ASP.Net. 我正在使用SharePoint Server 2007 + C#+ .Net 3.5 + VSTS 2008 + ASP.Net。 And I am using collaboration portal template. 我正在使用协作门户模板。

I am developing a custom aspx page and put it in _layout folder of a site and I want to apply default.master of the SharePoint site to this aspx page. 我正在开发一个自定义aspx页面,并将其放在网站的_layout文件夹中,我想将SharePoint网站的default.master应用于此aspx页面。 Any samples about how to achieve this goal? 关于如何实现此目标的任何样本?

如果使用SharePoint Designer,则可以右键单击页面,然后选择要应用的母版页。

You can put code in the PreInit event to make your custom page use the current site's masterpage. 您可以将代码放在PreInit事件中,以使您的自定义页面使用当前网站的母版页。

protected override void OnPreInit(EventArgs e)
{
 base.OnPreInit(e);
 SPWeb myWeb = SPControl.GetContextSite(Context).OpenWeb();
 string strUrl = myWeb.ServerRelativeUrl + "/_catalogs/masterpage/my.master";
 this.MasterPageFile = strUrl;
}

Or replace my.master with default.master in order to use the default master page. 或使用default.master替换my.master以便使用默认的母版页。 Or check spweb's MasterUrl property and use that instead. 或检查spweb的MasterUrl属性,然后改用它。

Either way it should get you going in the right direction. 无论哪种方式,它都可以使您朝正确的方向前进。

The best way to do this is by use of an HttpModule. 最好的方法是使用HttpModule。 This enables the use of your custom master page for all application pages (ie pages in the LAYOUTS folder). 这使您可以将自定义母版页用于所有应用程序页面(即LAYOUTS文件夹中的页面)。 It can be deployed using a feature and can be activated per web application (seeing as the httpmodule needs to be registered in the web.config it is web app scoped.) 可以使用功能对其进行部署,并且可以针对每个Web应用程序进行激活(请参阅http模块需要在Web应用程序范围内的web.config中进行注册。)

By making it web app scoped, your end users will have a uniform user experience, instead of that single page looking like the front end of the site while all the other (Out of the box) application pages are still using the default sharepoint application.master. 通过使其成为网络应用程序,您的最终用户将获得统一的用户体验,而不是看起来像网站前端的单个页面,而其他所有(开箱即用的)应用程序页面仍在使用默认共享点应用程序。主。

For a code example and a more in depth explanation, look here . 有关代码示例和更深入的说明,请参见此处

PS You are getting errors using the code above because of missing content placeholders. PS:由于缺少内容占位符,因此使用上面的代码会出现错误。 You need to create a copy of your custom master page. 您需要创建自定义母版页的副本。 Although styling can be the same, application pages use more/other ContentPlaceHolders than a front end master page. 尽管样式可以相同,但是应用程序页面比前端母版页面使用更多/其他ContentPlaceHolders。

Just copy your custom master page, rename it from CustomMaster.master to, say, CustomMasterEdit.master and use that for application page styling, SharePoint will throw an error telling you which placeholders are missing, keep adding the needed placeholders till the page works (there are 2 or 3 extra placeholders needed i believe). 只需复制您的自定义母版页,将其从CustomMaster.master重命名为,例如CustomMasterEdit.master,并将其用于应用程序页面样式,SharePoint就会抛出错误,告诉您缺少哪些占位符,继续添加所需的占位符,直到页面正常工作为止(我认为需要2或3个额外的占位符)。

PPS To make sharepoint display errors that make sense, go the web.config and look for the <SharePoint> tag and change the callstack attribute from false to true . PPS要使有意义的共享点显示错误,请转到web.config并查找<SharePoint>标记,并将callstack属性从false更改为true Then, look for the customErrors tag and set the mode attribute to "off" . 然后,查找customErrors标记并将mode属性设置为"off" To completely enable debugging, you can also enable ASP.NET tracing. 若要完全启用调试,还可以启用ASP.NET跟踪。 Of course you should NOT do this in your production environment.... 当然,您不应该在生产环境中这样做。

More info on modifying the web.config to make sharepoint display real error message can be found here . 此处可以找到有关修改web.config以使共享点显示真实错误消息的更多信息。

and

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM