这似乎是一个已经被问过/回答过很多次的问题。它不是。
开发环境: VS 2012 和 MVC 4。我正在使用内置的 IIS Express 来运行该应用程序。
这个错误直到昨天才发生。它突然开始发生,我被卡住了。奇怪的是它只发生在一种情况下。
当我尝试访问 http://localhost:49962/managescholars/
时,它显示错误
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
但是使用 http://localhost:49962/managescholars/Index
工作正常。同一 Controller 的其他操作方法也可以正常工作。例如 http://localhost:49962/managescholars/create
。所有其他 Controller 也能正常工作。
我尝试将以下内容添加到 web.config。
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true" />
<handlers/>
</system.webServer>
我也试过以管理员身份运行以下命令
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
但他们都没有工作。
编辑:
我已经修改了我的路线。它们看起来如下。
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 }
);
}
我正在使用 T4MVC
模板。
即使我在底部保留默认路由并删除前两条路由,它仍然不起作用。我做错了什么?
非常感谢您的帮助。
最佳答案
您的路线似乎没问题。这应该不会造成任何问题。该错误仅发生在 http://localhost:49962/managescholars/
上,这意味着可能存在一些其他同名资源。
你能确保你的代码在执行过程中不会错误地创建文件夹 managescholars 吗?”
关于c# - HTTP 错误 403.14 - 禁止访问 - 带 IIS Express 的 MVC 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17297490/