Asp.net mvc 返回路径作为MVC路由参数

Asp.net mvc 返回路径作为MVC路由参数,asp.net-mvc,asp.net-mvc-routing,Asp.net Mvc,Asp.net Mvc Routing,当我有这样一个URL时: http://localhost/dir1/dir2/file1.txt 我希望路径/dir1/dir2/file1.txt,作为参数传递给我的控制器操作 将我的默认路线更改为此将不起作用: routes.MapRoute( name: "Default", url: "{id}", defaults: new { controller = "FileSystem", action = "Deta

当我有这样一个URL时:

http://localhost/dir1/dir2/file1.txt
我希望路径
/dir1/dir2/file1.txt
,作为参数传递给我的控制器操作

将我的默认路线更改为此将不起作用:

routes.MapRoute(
            name: "Default",
            url: "{id}",
            defaults: new { controller = "FileSystem", action = "Details", id = UrlParameter.Optional }
        );

显然,路径中的斜杠导致了问题,但我无法对它们进行URL编码。有没有办法告诉路由引擎用斜杠抓取整个路径,并将其作为
id
传递给我的
文件系统
控制器的
详细信息
操作?

需要更详细地解释吗?与OP文章的唯一区别是星号(据我所知)。如果在最后一个url参数中使用星号,则路由将所有matchet数据作为一个参数进行匹配。例如,如果您有像/customer/111/details这样的url,那么路由url/customer/{id}根本不匹配,但是/customer/{*id}匹配它,并将111/details作为id值传递给我,我完全忽略了这一点。。。我刚刚读过Mike Wasson关于WebAPI 2中路由的一篇文章,它使用通配符映射通过斜杠传递日期时间。裁判:
routes.MapRoute(
            name: "Default",
            url: "{*id}",
            defaults: new { controller = "FileSystem", action = "Details", id = UrlParameter.Optional }
        );