【问题标题】:IIS 8 - Default Document - resource cannot be foundIIS 8 - 默认文档 - 找不到资源
【发布时间】:2013-06-01 20:12:24
【问题描述】:

我试图了解为什么在我浏览虚拟目录时我的默认文档没有出现。如果我按照我应该能够的方式浏览该网站,我会得到:


但是,如果我将页面添加到 URL,它就会出现:


一位SO answer 建议删除所有默认文档(在 IIS 中),但真正的文档除外。我试过了(下图),但没有帮助。


为什么 IIS 在使用根 URL (http://localhost/SignalRChat) 时不提供该页面?

这是删除默认文档后 web.config 的相关部分:

<defaultDocument>
    <files>
        <remove value="default.aspx" />
        <remove value="iisstart.htm" />
        <remove value="index.html" />
        <remove value="index.htm" />
        <remove value="Default.asp" />
        <remove value="Default.htm" />
        <add value="ChatPage.cshtml" />
    </files>
</defaultDocument>

这是处理程序部分:

<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*."
       verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
       modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
       preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*."
       verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
       modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
       preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
       verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler"
       preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

【问题讨论】:

  • 您想查看&lt;handlers&gt; 部分吗?
  • 如果我将 ChatPage.cshtml 的名称更改为 default.cshtml,它将自动显示。
  • 你可以尝试使用 列表下的 选项而不是单个页面删除吗?
  • 那些handlers 是有原因的吗?因为那些 ExtensionlessUrlHandler 处理程序只是忽略了您的 DefaultDocument 配置。
  • @Edward 我今晚可以试试。

标签: asp.net .net asp.net-mvc-4 iis iis-8


【解决方案1】:

当您的请求未指向 URL 末尾的特定文件名时,404 错误的另一个可能原因是您的 IIS 请求过滤规则拒绝无扩展名请求。

要确定它,请找出 404 错误的子代码。 通常是 404.7,但可能会有一些变化,

此外,您可以尝试显式允许无扩展请求,方法是将&lt;add fileExtension="." allowed="true" /&gt; 添加到您的 web.config,如下所示:

  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions>
          <add fileExtension="." allowed="true" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>

请让我知道它是否有帮助,或者将您的确切 404 错误与子代码一起发布。

【讨论】:

  • 帮我修好了!非常感谢。 IIS 8 上是否默认启用请求过滤? (因为我不必在 Windows 7/IIS 7.5 上这样做)
【解决方案2】:

从您的标签看来,您使用 MVC 和使用 razor 视图引擎 (cshtml) 的视图。在 MVC 中,URL 不会直接映射到文档。所以讨论不应该是关于默认文档、处理程序和 IIS 配置。

URL 必须与定义的路由匹配,该路由会调用控制器上的操作。然后,此操作将呈现视图 (*.cshtml)。

尝试修复您的路线以便能够处理请求。如果您需要更多帮助,您应该使用有关控制器和路线的更多信息来更新您的问题。

【讨论】:

    【解决方案3】:

    您可以制作网站/应用程序安装程序。它具有设置启动页面选择的选项。

    所以在安装程序中设置 ChatPage.cshtml 作为您的启动页面,如果您在安装后键入 localhost/SignalIRChat

    您将看到 ChatPage.cshtml 的内容,而不会在地址栏中显示“ChatPage.cshtml”名称。

    它将解决您的问题。

    【讨论】:

    • 谢谢,但我不想为此使用安装程序。我只是使用 VS 的 Publish 选项。现在,如果您知道安装程序做了什么来解决这个问题,那将会很有帮助。
    【解决方案4】:

    您需要在handlers 部分的末尾添加此Handler

    <add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
    

    更新:

    由于.cshtml文件默认被屏蔽,你需要:

        <handlers>
            <remove name="cshtml-ISAPI-4.0_64bit" />
            <remove name="cshtml-ISAPI-4.0_32bit" />
            <remove name="cshtml-Integrated-4.0" />
            <remove name="cshtm-ISAPI-4.0_64bit" />
            <remove name="cshtm-ISAPI-4.0_32bit" />
            <remove name="cshtm-Integrated-4.0" />
        </handlers>
    
        <staticContent>
            <mimeMap fileExtension=".cshtml" mimeType="text/html" />
        </staticContent>
    

    删除建议的 StaticFile 处理程序(如果仍然存在)。

    【讨论】:

    • 添加该处理程序后(没有type属性,因为IDE抱怨它),我得到一个错误:Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'StaticFile'我不知道为什么;没有另一个名为 StaticFile 的元素。
    • 我修改了我的答案。请看一下
    • 我尝试了你的建议。我仍然得到:The resource cannot be found. 感谢您的尝试。我已经准备好放弃了,只是把它命名为 Index 什么的。
    【解决方案5】:

    这可能是 MVC 问题。

    您可能需要从索引重定向到 SignalRChat 控制器中的其他操作。
    类似这样:

    public ViewResult Index()
    {
        return View("ChatPage");
    }
    

    【讨论】:

      【解决方案6】:

      您的目录浏览似乎在 IIS 中被禁用。刚刚在 IIS 中启用目录浏览。它会解决你的问题。

      访问http://technet.microsoft.com/en-us/library/cc731109%28v=ws.10%29.aspx了解更多详情。

      希望这会有所帮助。

      【讨论】:

      • 我真的不认为这应该是答案。首先,它没有用。其次,您提供的链接指出:Enable directory browsing when you want client browsers to display a Web page that lists the contents of a directory when a request does not specify a document name and IIS cannot return a default document. A default document cannot be returned when IIS does not find a file in the directory that matches a file name specified in the IIS default document list, or when the Default Document feature is disabled in IIS.我不想显示内容,我已经指定了默认文档。
      • 而且我还没有禁用默认文档功能。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多