看起来似乎这是一个已经被问答过很多次的问题,但实际上不是。
开发环境: 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
是可以的,同一控制器的其他动作方法也能正常工作,例如http://localhost:49962/managescholars/create
。所有其他控制器也能正常工作。
我已经尝试将以下内容添加到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
模板。
即使我把默认路由放在末尾并移除前两个路由,它仍然无法工作。我做错了什么?
非常感谢您的帮助。