我遇到路由问题,RouteConfig.cs
包含以下路由:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"TermsOfService",
"termsofservice",
new { controller = "Home", action = "TermsOfService" }
);
routes.MapRoute(
"PrivacyPolicy",
"privacypolicy",
new { controller = "Home", action = "PrivacyPolicy" }
);
routes.MapRoute(
"Contact",
"contact",
new { controller = "Home", action = "Contact" }
);
routes.MapRoute(
"Support",
"support",
new { controller = "Home", action = "Support" }
);
routes.MapRoute(
"ReadOurStory",
"readourstory",
new { controller = "Home", action = "ReadOurStory" }
);
routes.MapRoute(
name: "BlogItem",
url: "blog/{name}",
defaults: new { controller = "Home", action = "BlogItem" }
);
routes.MapRoute(
name: "ProductDetail",
url: "products/{name}",
defaults: new { controller = "Home", action = "Product" }
);
routes.MapRoute(
name: "Products",
url: "products",
defaults: new { controller = "Home", action = "Products" }
);
routes.MapRoute(
name: "Tutorials",
url: "tutorials",
defaults: new { controller = "Home", action = "Tutorials" }
);
routes.MapRoute(
name: "Blog",
url: "blog",
defaults: new { controller = "Home", action = "Blog" }
);
routes.MapRoute(
name: "TutorialDetail",
url: "tutorials/{name}",
defaults: new { controller = "Home", action = "Tutorial" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
以及HomeController
中的这两项操作:
public ActionResult Products()
{
var model = LoadItemsModel(ItemType.Product);
return View(model);
}
public ActionResult Tutorials()
{
var model = LoadItemsModel(ItemType.Tutorial);
return View(model);
}
现在产品链接正常运作:
http://localhost:61296/products/
但是教程的链接:
http://localhost:61296/tutorials/
返回错误
HTTP错误403.14 - 禁止
Web服务器配置为不列出此目录的内容
我尝试将测试路线更改为tutorials2
,将操作更改为Tutorials2
,然后此修改后的链接正常工作。我不知道为什么路线tutorials
不起作用。
答案 0 :(得分:3)
根据错误,我的猜测是你的项目文件夹中有一个名为"教程"的物理目录。任何物理文件/目录将始终否决任何路由。然后,由于默认情况下禁用目录列表,因此会收到403错误。删除或重命名物理目录,你应该没事。