1

我正在尝试使用 MVC 构建文件共享网站。短 URL 是一个不错的功能 - 通常采用以下格式:

http://site.com/Rtravf2
http://site.com/XddsvgF
http://site.com/AaraEwq

URL 末尾的“动作”实际上是用于下载文件的 ID。这种格式的 URL 都可以映射到家庭控制器中的同一个操作方法,称为下载。

这是我的路线表中唯一的路线

routes.MapRoute(
    "Default", // Route name
    "{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

我应该构造什么样的路由,以便这些 Url 可以映射到 Home Controller 上的 Download 操作。

目前得到一堆404(自然!)

感谢您的任何指示。

4

1 回答 1

0
routes.MapRoute(null, // Route name
    "{id}", // URL with parameters
    new { controller = "Home", action = "Download" }
);

routes.MapRoute(null, // Route name
    "Index/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
于 2012-06-01T19:13:56.697 回答