【问题标题】:ASP.NET Master page not loadingASP.NET 母版页未加载
【发布时间】:2014-09-25 20:56:44
【问题描述】:

我的网站出现以下错误:

内容控件仅允许在引用 母版页。

这是它尝试加载的文件的内容:

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

Default.master 确实存在于请求的位置并且确实包含:

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

为什么子页面无法识别/加载母版页?

谢谢!


更新 - 这是堆栈跟踪和 .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

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

【问题讨论】:

  • 您确定是哪一行/文件引发了错误吗?您确定服务器上的文件与您正在查看的文件相符吗?
  • 没有得到行号,我直接在服务器上编辑文件。
  • 母版页是否有

标签: asp.net master-pages


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    对于您拥有的内容页面

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

    你是编辑过的还是准确的?也许它需要一个完全封闭的标签?

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

    【讨论】:

      【解决方案3】:

      感谢大家的帮助,但最终发现没有人能够根据我提供的信息解决此问题。我没有编写这段代码,但我坚持维护它,这是我第一次看到这个网站。

      事实证明,在 web.config 中,有一个类被定义为所有页面的基本类型。此类正在根据数据库查询的结果覆盖 MasterPageFile 属性,在本例中,该查询返回一个空结果。

      因此,我将在此处发布此作为答案,以防有人遇到似乎不可能的事情 - 特别是在维护遗留代码时。检查 web.config。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-27
        • 2018-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-11
        相关资源
        最近更新 更多