【问题标题】:Web.Config Runtime Error, Server Error in '/' ApplicationWeb.Config 运行时错误,“/”应用程序中的服务器错误
【发布时间】:2015-10-21 16:46:31
【问题描述】:

我正在尝试创建一个非常简单的 asp.net masterpage 站点,在我上传到主机之前一切顺利。使用以下 web.config

<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration> 

我被告知要添加

<customErrors mode="Off"/>  

当我添加时

<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" />
  <customErrors mode="Off"/>
</system.web>

我收到新错误

在母版页“/MasterPage.master”中找不到 ContentPlaceHolder“ContentPlaceHolder1”,请在内容页中验证内容控件的 ContentPlaceHolderID 属性。

母版页代码似乎是正确的

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>test_configprob02</title></head>
<body>
<form id="mainForm" runat="server">

    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

    </asp:ContentPlaceHolder>

</form></body></html>

default.aspx 代码

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>Lorem ipsum dolor  ipsum.</p>
</asp:Content>

难倒。

这是浏览器中显示的内容-

“/”应用程序中的服务器错误。

Cannot find ContentPlaceHolder 'bodyPL' in the master page '/MasterPage.master', verify content control's ContentPlaceHolderID attribute in the content page.

说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: System.Web.HttpException: Cannot find ContentPlaceHolder 'bodyPL' in the master page '/MasterPage.master', verify content control's ContentPlaceHolderID attribute in the content page.

来源错误:

在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

堆栈跟踪:

[HttpException (0x80004005): Cannot find ContentPlaceHolder 'bodyPL' in the master page '/MasterPage.master', verify content control's ContentPlaceHolderID attribute in the content page.]
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +797
   System.Web.UI.Page.get_Master() +54
   System.Web.UI.Page.ApplyMasterPage() +14
   System.Web.UI.Page.PerformPreInit() +45
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +335

版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.34249

【问题讨论】:

  • 母版页中是否有“bodyPL”?如果不是这样就可以解释了。
  • @tpugh 将此&lt;asp:ContentPlaceHolder ID="head" runat="server"&gt; &lt;/asp:ContentPlaceHolder&gt; 添加到内容上方的主页面和默认页面中

标签: c# asp.net .net


【解决方案1】:

尝试为 ContentPlaceHolder 控件提供一个新的 id,例如“body”,然后重置 Content 控件的 ContentPlaceHolderId 属性,看看它在哪里,我也看不出它有什么问题。

编译项目时是否有任何构建错误?

顺便说一句,如果你不知道,如果你知道,请道歉;

自定义错误是您可以设置的网络配置中的设置

关闭 - 将显示 .net 错误消息,例如您看到的错误消息。

开启 - 这将允许您为特定错误代码指定重定向到自定义页面,例如:

RemoteOnly - 这将允许您在网站所在的服务器上查看错误消息,但仍向访问者显示您的自定义错误页面

另外很高兴知道:您可以为错误设置默认网址

进一步阅读:

https://msdn.microsoft.com/en-gb/library/h0hfz6fc(v=vs.85).aspx

希望这会有所帮助。

【讨论】:

  • 我更改了 masterpage 上的 ContentPlaceHolder ID 和 default.aspx 上的 ContentPlaceHolderID,不走运,得到同样的错误。不,我在 Visual Studio 2013 中编译时没有错误,只有在上传到主机之后。
  • 奇怪啊!请把您在浏览器中看到的错误信息贴出来好吗?
【解决方案2】:

如果它在您的本地环境而不是主机上运行,​​则可能是主机环境。确认您的应用程序池已设置为使用正确的 .net 框架运行。此外,确认托管管道模式为“集成”。

是否曾经有一个名为“bodyPL”的元素?

【讨论】:

  • IIS:7.0,ASP.Net 运行时版本:4.0/4.5,管道处于集成模式。我与主持人(godaddy)交谈,他们没有发现任何问题。我使用非母版页网站进行了测试,它运行良好。根据之前的建议,我将 ContentPlaceHodler ID 更改为 bodyPL
猜你喜欢
  • 1970-01-01
  • 2018-07-07
  • 2017-09-18
  • 2015-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-20
  • 2012-11-02
相关资源
最近更新 更多