MVC5 和动态路由问题

MVC5 and Dynamic Route issues

我有一个非常奇怪和烦人的问题,我迫切需要一些帮助。我有一个动态路由,所有请求都将在我的 MVC 应用程序中通过。路线看起来像这样

routes.MapRoute(
                "FirstSpirit",
                "{locale}/{*PageUrl}",
                new { controller = "Site", action = "Page" },
                new { PageUrl = @"^(.*)?$" } //^(.*)?$
                );

这很好,但是发生了 2 件事,我找不到直接的答案。

首先,如果值为 "en",则不会填充 {locale} 参数。例如,如果我使用 URL http://domain.com/es/index.html then the value "es" comes through in the routedata values. However if i use the URL http://domain.com/en/index.html,则值 "en" 不会通过。这适用于所有其他值,但 "en" 我不知道为什么。

我遇到的另一个问题是我需要能够使用相同的路径在 URL 中传递 .html,但是如果我在我的路径中使用 .html 扩展名URL MVC 应用程序自动抛出 404 并且没有命中我的任何路由或控制器。

有人可以帮助我吗,因为我对此有点疯狂。抱歉,如果之前已经回答过这个问题,但我找不到关于这些问题的任何信息。

谢谢

我有幸查看了应用程序源代码。有趣的是,路由对我来说工作正常。

此问题已在 Windows Server 2012 R2 Data Center (.NET v4.6 [393297]) 上重复出现。

我无法在 Windows 10 (.NET v4.6 [393295]) 上复制。

我从 web.config 中删除了以下内容:

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>

已添加:

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

并将 targetFramework 从 4.5.2 更改为 4.5

此更改似乎解决了 IIS 未将所有请求路由到应用程序这一事实。但是,"en" 仍在从控制器操作作为捕获所有参数接收的 url 中删除。这仅在 "en/" 是 url 路径的第一部分时被删除。

例如

/something/en/index.html 解析为 "something/en/index.html"。 /en/index.html 解析为 "index.html".