繁体   English   中英

一条ASP.NET MVC路由不起作用

[英]One ASP.NET MVC route not working

我对路由有问题, 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不起作用。

基于该错误,我的猜测是您的项目文件夹中有一个物理目录,称为“ tutorials”。 任何物理文件/目录将始终否决任何路由。 然后,由于默认情况下目录列表处于禁用状态,因此会出现403错误。 删除或重命名物理目录,就可以了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM