0

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

我如何解决这个小问题?

4

3 回答 3

0

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

建议:

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

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

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

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

  5. 如果它仍然不起作用,请剪切/粘贴:

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

    b) 确切的错误信息

还:

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

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

于 2012-07-15T19:55:25.523 回答
0

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

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

<defaultDocument>
      <files>
        <clear />
        <add value=*"Defalut.aspx"* />
      </files>
    </defaultDocument>
于 2012-07-15T21:12:43.393 回答
0

我知道聚会迟到了,但是对于仍然遇到类似问题的任何人,我认为这与默认页面名称的拼写无关(访问时可能只会给出 404)。

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

因此,您的示例配置文件应类似于:

<?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>
于 2018-05-15T11:09:24.133 回答