简体   繁体   English

ASP.NET母版页未加载

[英]ASP.NET Master page not loading

I have a site that is giving me the following error: 我的网站给我以下错误:

Content controls are allowed only in content page that references a master page. 仅在引用母版页的内容页中允许内容控件。

Here is the contents of the file it is trying to load: 这是它尝试加载的文件的内容:

<%@ Page Language="c#" MasterPageFile="~/shared/templates/Default.master" %>
<asp:Content ID="PageContent" runat="server" ContentPlaceHolderID="PageContentPlaceHolder" />

Default.master does exist in the location requested and does contain: Default.master确实存在于所请求的位置,并且包含:

<asp:ContentPlaceHolder runat="Server" ID="PageContentPlaceHolder" />

Why is the child page not recognizing/loading the master page? 为什么子页面无法识别/加载母版页面?

Thanks! 谢谢!


UPDATE - Here is the stack trace and .NET Version info: UPDATE-这是堆栈跟踪和.NET版本信息:

[HttpException (0x80004005): Content controls are allowed only in content page that references a master page.]
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +11119902
   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

Version Information: Microsoft .NET Framework Version:2.0.50727.5485; 版本信息:Microsoft .NET Framework版本:2.0.50727.5485; ASP.NET Version:2.0.50727.5483 ASP.NET版本:2.0.50727.5483

母版页应与该页位于同一IIS应用程序中。

for the content page you have 对于您拥有的内容页面

<asp:Content ID="PageContent" runat="server" ContentPlaceHolderID="PageContentPlaceHolder" />

did you edited that or is it exact? 您是编辑过的还是确切的? maybe it needs a fully closed tag? 也许它需要一个完全封闭的标签?

<asp:Content ID="PageContent" runat="server" ContentPlaceHolderID="PageContentPlaceHolder">
    content
</asp:Content>

Thanks everyone for your help, but in the end it turned out nobody would have been able to solve this with the information I provided. 感谢大家的帮助,但最终结果是,没有人能够使用我提供的信息来解决这个问题。 I did not write this code, but I'm stuck with maintaining it and this is the first I'd seen this site. 我没有编写此代码,但是我坚持维护它,这是我第一次看到此站点。

As it turns out, in the web.config, there was a class defined as a base type for all pages. 事实证明,在web.config中,有一个类定义为所有页面的基本类型。 This class was overwriting the MasterPageFile attribute based on the results of a database query which, in this case, was returning an empty result. 此类正在基于数据库查询的结果覆盖MasterPageFile属性,在这种情况下,该查询将返回空结果。

So, I'll post this as the answer here in case anyone is experiencing something that seems impossible - especially when maintaining legacy code. 因此,如果有人遇到似乎不可能的事情,特别是在维护旧代码时,我将在此处发布此作为答案。 Check the web.config. 检查web.config。

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

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