【发布时间】:2020-11-18 11:19:25
【问题描述】:
我有以下网址:
/Meetings/doc1.pdf
/Meetings/doc2.pdf
我尝试在我的 RouteConfig 中设置以下内容
var route = routes.MapRoute(
name: "RedirectMeetingDocs",
url: "Meetings/{filename}",
defaults: new { action= "GetAttachmentByName", controller = "Generic" },
constraints: new { filename = @"(.*?)\.(pdf|ppt)" }
);
具有以下功能:
[HttpGet]
public ActionResult GetAttachmentByName(string fileName)
{
...
}
但是,它从来没有工作,我不断收到 404 错误。
我也试过了:
var route = routes.MapRoute(
name: "RedirectMeetingDocs",
url: "Meetings/{filename}.{extension}",
defaults: new { action= "GetAttachmentByName", controller = "Generic" },
constraints: new { filename = new AlphaRouteConstraint(), extension = new AlphaRouteConstraint() }
);
与
public ActionResult GetAttachmentByName(string fileName, string extension)
{
但没有任何效果。
有什么建议吗?
【问题讨论】:
标签: asp.net-mvc routes