【问题标题】:The element 'system.web' has invalid child element 'defaultDocument'元素“system.web”具有无效的子元素“defaultDocument”
【发布时间】:2012-07-15 19:47:49
【问题描述】:

我正在训练我的 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 文件并且我无法在我的托管公司的服务器上运行任何脚本) , 没用。

如何解决这个小问题?

【问题讨论】:

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


    【解决方案1】:

    “Defalut.aspx”是一个明确的黄色标志。

    建议:

    1. 只需使用 MSVS2012 创建一个新的虚拟项目(我手头没有副本,所以暂时无法帮助您)

    2. 将自动生成的“web.config”剪切并粘贴到您的项目中,并验证它是否有效。 如果没有,ONLY 进行那些 MINIMAL 更改以获得干净的编译/执行。

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

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

    5. 如果还是不行,请剪切/粘贴:

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

      b) 确切的错误信息

    还有:

    问:它现在 BOTH 您的 MSVS2012(在本地运行)您的目标 Web 服务器失败,对吗?

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

    【讨论】:

    • 感谢拼写错误检测。好眼睛!
    • 我按照您的要求做了(无需进行任何更改)并使其与 web.config 的“新”版本一起工作。然后我添加了 defaultDocument 标记并得到了我将在下一条评论中粘贴的消息。
    • 元素“system.web”的子元素“defaultDocument”无效。预期的可能元素列表:
    • 'anonymousIdentification,身份验证,授权,browserCaps,clientTarget,编译,customErrors,部署,deviceFilters,fullTrustAssemblies,全球化,healthMonitoring,hostingEnvironment,httpCookies,httpHandlers,httpModules,httpRuntime,identity,machineKey,membership,mobileControls 、页面、partialTrustVisibleAssemblies、processModel、profile、roleManager、securityPolicy、sessionPageState、sessionState、siteMap、trace、trust、urlMappings、webControls、webParts、webServices、xhtmlConformance、缓存'。 C:\...\Web.config
    • 它还列出了我在下面的评论中提到的错误消息。它说:“无法识别的配置部分 system.web/defaultDocument.C:\...\Web.config”(省略号是出于可读性原因)
    【解决方案2】:

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

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

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

    【讨论】:

    • 这绝对是一个问题区域,但我认为这不是我的问题的原因,因为错误消息抱怨标签未被识别,而不是文件未被找到。
    • 事实上VS非常清楚地指出“无法识别的配置部分system.web/defaultDocument。”另外我已经更正了拼写,错误仍然存​​在。
    【解决方案3】:

    派对迟到了,我知道,但对于仍然遇到类似问题的任何人,我认为这与默认页面名称的拼写无关(访问时可能只会给出 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>
    

    【讨论】:

      猜你喜欢
      • 2016-10-23
      • 2021-03-01
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 2021-05-28
      • 2012-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多