【问题标题】:ASP.NET MVC5 The webserver is not configured for the requested URL, and directory browsing is not enabled on the serverASP.NET MVC5 没有为请求的 URL 配置网络服务器,并且服务器上没有启用目录浏览
【发布时间】:2015-11-20 13:44:25
【问题描述】:

我在从 MVC5 应用程序加载页面时遇到问题。

我已经安装并使用了这个软件:

  • Windows 10
  • Visual Studio 企业版 2015
  • 微软 IIS 10.0 Express
  • 带有实体框架的 MVC 5

到目前为止,一切正常,我能够显示该网站。 在创建模型和使用实体框架的控制器之后,我收到此错误消息。

HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.

Most likely causes:

    A default document is not configured for the requested URL, and directory browsing is not enabled on the server.


Things you can try:

    If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
    Enable directory browsing.
        Go to the IIS Express install directory.
        Run appcmd set config /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the server level.
        Run appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the site level.
    Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.

Detailed Error Information:
Module     DirectoryListingModule
Notification       ExecuteRequestHandler
Handler    StaticFile
Error Code     0x00000000
Requested URL      http://localhost:2063/
Physical Path      c:\users\johan\documents\visual studio 2015\Projects\MvcMovie2\MvcMovie2
Logon Method       Anonymous
Logon User     Anonymous
Request Tracing Directory      C:\Users\johan\Documents\IISExpress\TraceLogFiles\MVCMOVIE2

所以首先我从错误消息给我的建议开始。

这两个都很好。
- cd 进入 IIS Express 安装目录
- appcmd set config /section:system.webServer/directoryBrowse /enabled:true

然后我尝试运行这个命令:
appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true

我将["SITE_NAME"] 替换为:
- ["SITE_NAME"]
- ["localhost"]
- ["MovieDb2"]
- "MovieDb2"
- [MovieDb2]
- MovieDb2
他们都没有工作,我收到一条错误消息:
ERROR ( message:Cannot find SITE object with identifier ["SITE_NAME"]

我已经找到了很多文档,但都可以追溯到.ASPX 格式和旧版本的 IIS Express。

在 Visual Studio 中,我右键单击应用程序的 index.cshtml 文件之一,然后单击“设置为起始页”
即使在重建之后,这也不起作用。

接下来我发现了一些信息,您必须在 IIS 管理器中进行一些更改。我搜索了很多,但我找不到 IIS 管理器。
即使使用此链接:https://msdn.microsoft.com/nl-nl/library/bb763170.aspx
命令inetmgr 只返回一个错误。

我在 Web.config 中添加了以下代码:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

那也没有解决问题。

之后我按照此页面中的步骤操作:HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory

但是我还必须进入 IIS 管理器,我无法找到它。

我真的希望有人对此有解决方案。
提前致谢。

【问题讨论】:

  • 听起来 ASP.NET MVC 没有在 IIS Express 上正确注册,这很奇怪。您必须使用 Jexus Manager 等工具来检查应用程序池设置,以查看是否配置了 CLR 版本 4。

标签: c# asp.net-mvc iis


【解决方案1】:

你的根目录是空的?(index.html,index.aspx vb.) 我认为你的项目web.config默认文档属性没有设置。

目录浏览 Web.config 属性

    <configuration>

  <location path="special_directory_name_here">
   <system.webServer>
    <directoryBrowse enabled="true" />
   </system.webServer>

  </location>
</configuration>

请配置为您的项目默认路由设置,因为您的默认路由设置不会重定向到控制器。

更改默认路由设置

http://blogs.msdn.com/b/prakasht/archive/2013/08/08/change-the-default-route-in-asp-net-mvc.aspx

默认文档属性 web.config

<configuration>
   <system.webServer>
    <defaultDocument>
        <files>
            <add value="index.php" />
        </files>
    </defaultDocument>
   </system.webServer>
</configuration>

【讨论】:

    【解决方案2】:

    我终于明白了。 我所要做的就是更改 RouteConfig.cs 中的 url

    来自
    url: "{controller}/{action}/{name}/{id}"

    url: "{controller}/{action}",

    【讨论】:

      【解决方案3】:

      这是用于快速应用测试目的的快速解决方案,并非旨在解决根本原因 - 不是 MVC

      【讨论】:

        【解决方案4】:

        以下是解决我的具体问题的方法:

        在 Visual Studio 中,右键单击网站项目 > 属性 > Web > 选择“特定页面”> 浏览 > 选择默认页面。

        如果您使用的是 MVC 5 或更高版本,请确保删除移动“.cshtml”并删除 Views 目录。例如,该目录将显示为 Views/ControllerName/Index.cshtml。删除视图,使其显示为 ControllerName/Index

        【讨论】:

          【解决方案5】:

          在 App_start 文件夹中向 RouteConfig.cs 添加特定地图路线后,我的问题就消失了

          'routes.MapRoute("买地", // 字符串名称 "BuyLands/Index", // 字符串 URL 新的 { 控制器 = "BuyLands", 操作 = "索引" });

          // 控制器名称为 BuyLands'

          【讨论】:

            猜你喜欢
            • 2011-06-06
            • 2017-07-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多