元素'system.web'具有无效的子元素'defaultDocument'

时间:2012-07-15 19:47:50

标签: asp.net web-config asp.net-4.0 visual-studio-2012

我正在训练我的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>
  <appSettings/>
  <system.web>

    <defaultDocument>
      <files>
        <clear />
        <add value="Defalut.aspx" />
      </files>
    </defaultDocument>

    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
    <machineKey/>
    <customErrors defaultRedirect="Error.aspx" mode="On"/>
  </system.web>
</configuration>

问题是VS2012(Express)将其标记为蓝色并声明主题中的错误。首先,我认为我可以按原样上传它,并通过蛮力使服务器喜欢该文件,但它然后生气并吐出以下

HTTP错误500.19 - 内部服务器错误 无法访问请求的页面,因为页面的相关配置数据无效。

当我阅读错误消息时,它说:“无法读取配置部分'defaultDocument',因为它缺少部分声明。”

我已经完成了我的作业并找到了下面的文章,但由于我的情况有限(例如我需要手动上传web.config文件,我无法在我的托管公司的服务器上运行任何脚本) ,但没有用。

我如何解决这个小问题?

3 个答案:

答案 0 :(得分:0)

“Defalut.aspx”是一个明确的黄旗。

建议:

  1. 使用MSVS2012创建一个新的虚拟项目(我没有方便的副本,所以我暂时无法帮助你)

  2. 将自动生成的“web.config”剪切并粘贴到项目中,并验证其是否有效。 如果没有,请进行干净编译/执行所需的 MINIMAL 更改。

  3. 保存工作web.config的备份

  4. 尝试添加“defaultDocument”部分,看看会发生什么。

  5. 如果仍然无效,请剪切/粘贴:

    a)确切的部分(正如我上面假设的那样)

    b)确切的错误消息

  6. ALSO:

    问:现在 BOTH 你的MSVS2012(本地运行) AND 你的目标网络服务器失败了吗?

    问:您确定目标Web服务器是否支持ASP.Net 4.0?

答案 1 :(得分:0)

您的配置看起来正确但发生错误是因为它无法找到意味着作为所有网站文件夹的默认文档的文件

所以请将“Defalut.aspx”替换为下面xml文件的正确拼写

<defaultDocument>
      <files>
        <clear />
        <add value=*"Defalut.aspx"* />
      </files>
    </defaultDocument>

答案 2 :(得分:0)

我知道,在派对上晚了,但是对于仍有类似问题的人,我不认为这与默认页面名称的拼写有任何关系(在访问时可能会给出404)

真正的问题是defaultDocument部分实际上应该在system.webServer下,而不是system.web。有关详细信息,请参阅defaultDocument Element

因此,您的示例配置文件应如下所示:

<?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>
  <appSettings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
    <machineKey/>
    <customErrors defaultRedirect="Error.aspx" mode="On"/>
  </system.web>
  <system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="Defalut.aspx" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>
相关问题