ASP.NET MVC5未针对请求的URL配置Web服务器,并且未在服务器上启用目录浏览

我有一个从MVC5应用程序加载页面的问题。

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

  • Windows 10
  • Visual Studio Enterprise 2015
  • Microsoft IIS 10.0 Express
  • 带有entity framework的MVC 5

到现在为止一切正常,我能够显示网站。 在创建模型之后,使用entity framework的控制器之后我收到了此错误消息。

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我添加了这段代码:

    

这也没有解决问题。

之后,我按照此页面中的步骤操作: HTTP错误403.14 – 禁止Web服务器配置为不列出此目录的内容

但在那里我还必须进入IIS管理器,我无法找到。

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

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

目录浏览Web.config属性

         

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

更改默认路线设置

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

默认文档属性web.config

          

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


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

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

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

  • ASP.NET应用程序在http:// localhost:port#/启动时的错误

  • 当URL更改为http:// localhost:45269 / HTMLPageName.html时工作

这是解决我的具体问题的原因:

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

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