C# HTTP 错误 403.14 - Forbidden - MVC 4 with IIS Express
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17297490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTTP Error 403.14 - Forbidden - MVC 4 with IIS Express
提问by Aamir
This seems like a question that has already been asked/answered many times. Its not.
这似乎是一个已经被问过/回答过很多次的问题。它不是。
Development Environment:VS 2012 and MVC 4. I am using the built in IIS Express to run the app.
开发环境:VS 2012 和 MVC 4。我使用内置的 IIS Express 来运行应用程序。
This error was not occurring until yesterday. It suddenly began to occur and I am stuck. Its strange that It occurs only in ONE scenario.
这个错误直到昨天才发生。它突然开始发生,我被卡住了。奇怪的是它只发生在一种情况下。
When I try to access http://localhost:49962/managescholars/, it shows me the error
当我尝试访问时http://localhost:49962/managescholars/,它显示了错误
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
But using http://localhost:49962/managescholars/Indexworks fine. Other action methods of same controller also work fine. such as http://localhost:49962/managescholars/create. All other controllers work fine as well.
但是使用http://localhost:49962/managescholars/Index效果很好。同一控制器的其他操作方法也可以正常工作。比如http://localhost:49962/managescholars/create. 所有其他控制器也能正常工作。
I have tried adding the following to web.config.
我尝试将以下内容添加到 web.config。
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true" />
<handlers/>
</system.webServer>
I also have tried running the following command as administrator
我也试过以管理员身份运行以下命令
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
But none of them worked.
但他们都没有工作。
Edit:
编辑:
I have modified my routes. They look as follows.
我已经修改了我的路线。它们如下所示。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "ManageScholarLectures",
url: "Manage/Lectures/{userFriendlyName}",
defaults: new { controller = MVC.ManageLectures.Name ,
action = MVC.ManageLectures.ActionNames.Index,
userFriendlyName = UrlParameter.Optional }
);
routes.MapRoute(
name: "ManageScholarEdit",
url: "Manage/Scholars/{userFriendlyName}",
defaults: new { controller = MVC.ManageScholars.Name,
action = MVC.ManageScholars.ActionNames.Edit }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = MVC.Home.Name,
action = MVC.Home.ActionNames.Index,
id = UrlParameter.Optional }
);
}
I am using T4MVCtemplate.
我正在使用T4MVC模板。
It still does not work even if I leave the default route at the bottom and remove the first two routes. What have I done wrong?
即使我将默认路由保留在底部并删除前两条路由,它仍然不起作用。我做错了什么?
Thanks a lot in advance for your help.
非常感谢您的帮助。
采纳答案by Yaqub Ahmad
Your routes seems fine. This should not cause any problem. The error is occuring only on http://localhost:49962/managescholars/which means that there might be some other resource with same name.
Can you make sure your code does not mistakenly creates a folder managescholarsduring execution?"
你的路线看起来不错。这应该不会造成任何问题。错误仅发生在http://localhost:49962/managescholars/这意味着可能存在同名的其他资源上。你能确保你的代码在执行过程中不会错误地创建一个文件夹managescholars吗?”
回答by tymtam
Firstly, I'm assuming that
首先,我假设
http://localhost:49962/managescholars/
is in fact
事实上
http://localhost:49962/manage/scholars/
. If not there's your problem :)
. 如果没有,那就是你的问题:)
I'm not an expert on routes, but in your route for Scholarsthe userFriendlyNameparam is not optional which means that http://localhost:49962/manage/scholars/won't match any of your rules and IIS will treat it a request to list the content of the folder.
我不是路由方面的专家,但在你的路由中Scholars,userFriendlyName参数不是可选的,这意味着它http://localhost:49962/manage/scholars/与你的任何规则都不匹配,IIS 会将它视为列出文件夹内容的请求。
回答by Pomme De Terre
In case someone get the same problem I got and enter this page deseperatly. If debugging website works but not on one website :
万一有人遇到我遇到的相同问题并绝望地进入此页面。如果调试网站有效但不在一个网站上:
Check modification on global.asax Check if the route configuration is still present...
检查 global.asax 上的修改 检查路由配置是否仍然存在...
I know it's dumb but lost 6 hours after a git merge...
我知道这很愚蠢,但在 git 合并后丢失了 6 小时...
回答by Anand
I know original question is answered but below worked in my case. I got exact same issue on VS2013 using IIS Express. In my case visiting /Login was not getting Index action in LoginController. There was no physical folder when I checked but after more digging I found there was virtual directory created on IIS Express for /Login path which caused this. I deleted the virtual directory from applicationhost config(Documents\IISExpress\config) to resolve issue.
我知道原来的问题得到了回答,但下面在我的情况下有效。我在使用 IIS Express 的 VS2013 上遇到了完全相同的问题。在我的情况下,访问 /Login 没有在 LoginController 中获得索引操作。我检查时没有物理文件夹,但经过更多挖掘后,我发现在 IIS Express 上为 /Login 路径创建了虚拟目录,这导致了这个问题。我从 applicationhost config(Documents\IISExpress\config) 中删除了虚拟目录来解决问题。
回答by Ivan Silva Lemos
I encountered the same problem. To solve is very easy.
我遇到了同样的问题。解决起来非常容易。
This problem occurs because of an IIS Express conflict when you edit the properties in the Protect URL in the Project settings. To solve this problem is very easy:
当您在项目设置中的保护 URL 中编辑属性时,发生此问题是由于 IIS Express 冲突。解决这个问题很简单:
1 - Look for the file "applicationhost.config" in the ".vs \ config" directory. This folder is at the root of the solution. You can open it using Notepad ++
1 - 在“.vs \ config”目录中查找文件“applicationhost.config”。此文件夹位于解决方案的根目录。您可以使用记事本++打开它
2 - Search for the name of your control using 'find' of your program (Ctrl + F). In my case, the control that gave problem was the 'Offices'.
2 - 使用程序的“查找”(Ctrl + F)搜索控件的名称。就我而言,出现问题的控件是“办公室”。
3 - Delete any node where you place the IIS settings for such a URL. See example below:
3 - 删除您为此类 URL 放置 IIS 设置的任何节点。请参阅下面的示例:
<site name="G4.Admin(1)" id="8">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projetos\PortalG4\src\G4.Admin" />
<virtualDirectory path="/Offices/Edit" physicalPath="C:\Projetos\PortalG4\src" />
<virtualDirectory path="/Offices" physicalPath="C:\Projetos\PortalG4" />
</application>
<application path="/Offices/Edit/2" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projetos\PortalG4\src\G4.Admin" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:6920:localhost" />
</bindings>
</site>
You should delete every element
你应该删除每个元素
<site name = "NAME_PROJECT" id = "X">
Note: Make a backup of the file before making the changes.
注意:在进行更改之前备份文件。
Hugs
拥抱
回答by Ivan Silva Lemos
Great !! In my case it was because I configured the application to run in a wrong url, but when I returned to the correct one, the look did not overwhelm the applicationhost.config.
伟大的 !!就我而言,这是因为我将应用程序配置为在错误的 url 中运行,但是当我返回到正确的 url 时,外观并没有淹没 applicationhost.config。
As I said above, I only managed to solve those steps.
正如我上面所说,我只设法解决了这些步骤。
回答by Fl4v
In my case, with Visual Studio 2015, I solved the problem with the following steps:
就我而言,使用 Visual Studio 2015,我通过以下步骤解决了该问题:
- Stop IIS Express
- Close Visual studio
- Delete file applicationhost.config in {my solution directory}.vs\config
- Delete directory Documents\IISExpress\config
- Start VS, F5 and enjoy :)
- 停止 IIS Express
- 关闭视觉工作室
- 删除{我的解决方案目录}.vs\config 中的文件 applicationhost.config
- 删除目录 Documents\IISExpress\config
- 启动 VS、F5 并享受 :)
回答by Steferson
In my case, after using @Fl4v answer, I search for directoryBrowseattribute on file applicationhost.config in {my solution directory}.vs\config and there was false. Changed to true, restart iis and now it finnally works.
就我而言,在使用 @Fl4v 答案后,我在 {my solution directory}.vs\config 中的文件 applicationhost.config 上搜索directoryBrowse属性,结果为 false。更改为true,重新启动iis,现在它终于可以工作了。
回答by Sneaky Anand
You Should Go the username/ and enable it if not enable.
如果没有启用,你应该去用户名/并启用它。

