如何编写捕获* .php的路由?

时间:2011-08-25 18:09:14

标签: c# asp.net-mvc-3 routes

我想制作一条捕捉所有“php”文件的路线......我试过了:

routes.MapRoute("php", "{*x}.php", new { controller = ... });

但我得到以下例外:

A path segment that contains more than one section, such as a literal section
or a parameter, cannot contain a catch-all parameter.
Parameter: routeUrl

必须抓住:

/p1/p2/p3.php
/p1/p2.php
/p1.php

我想编写一条可以捕获N级别的规则......我该怎么做?

1 个答案:

答案 0 :(得分:6)

您可以使用约束:

routes.MapRoute("php", "{*allphp}", new { ... }, new { allphp = @".*\.php" });

如果您仍然有默认路线,则必须放在此之前。

我的回答基于:Make routing ignore requests for a file extension