【问题标题】:ASP.NET MVC 3 Routing issue in Area区域中的 ASP.NET MVC 3 路由问题
【发布时间】:2012-09-17 11:48:56
【问题描述】:

我有一个非常奇怪的路由问题。

我有一个使用区域的 ASP.NET MVC 3 站点。 我在资产区域设置了以下路线:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        null,
        "Assets/{controller}/{action}/{code}",
        null,
        new { code = @"(\w{2,3}$)" }
    );

    context.MapRoute(
        "Assets_default",
        "Assets/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );
}

当我请求以下 URL 时,它可以正常工作

http://site.com/Assets/Gallery/GetByCode/AEP
http://site.com/Assets/Gallery/GetByCode/MEC
http://site.com/Assets/Gallery/GetByCode/GP
http://site.com/Assets/Gallery/GetByCode/BR2 
http://site.com/Assets/Gallery/GetByCode/ZZZ 
http://site.com/Assets/Gallery/GetByCode/123

但当我请求此 URL 时,我收到“404 - 找不到资源”错误

http://site.com/Assets/Gallery/GetByCode/PRN
http://site.com/Assets/Gallery/GetByCode/prn

我尝试过的所有其他 URL 都有效 - 似乎只是 PRN 有问题。

我在 GalleriesController > GetByCode 操作的开头放置了一个断点,而 PRN 路由甚至没有尝试进入该操作(正如 404 错误所暗示的那样)。

有没有人知道为什么 PRN 在路由中不起作用?或者我还能尝试调查什么?

感谢您的帮助 萨安

【问题讨论】:

  • 您的Index 操作是否会被击中?
  • 您是否尝试过删除路线上的正则表达式限制?您是否也尝试过将参数按照与默认路由相同的顺序放置?
  • 是的,尝试硬编码 context.MapRoute(null, "Assets/Gallery/GetByCode/PRN", new {controller="Gallery", action="GetByCode", code="PRN ");还是不行
  • 哇。这很奇怪。不知道那里发生了什么!对不起!

标签: asp.net-mvc-3 routing asp.net-mvc-routing asp.net-mvc-3-areas


【解决方案1】:

这可能与您无法在 Windows 文件系统上创建文件夹“prn”有关。我的猜测是 IIS 使用 windows 文件系统的方式使得这个问题与上述问题产生了共鸣。

其实这篇文章可能对你有帮助:ASP.NET MVC Routing vs. Reserved Filenames in Windows

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 2011-11-15
    相关资源
    最近更新 更多