【问题标题】:RouteConfig and filename with extension - MVC5RouteConfig 和带有扩展名的文件名 - MVC5
【发布时间】: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


    【解决方案1】:

    好的,我通过在我的 Web.config 中添加以下内容来解决它:

    <add name="IATTCRedirectOldMeetingFiles" path="meetings/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    

    现在,上面显示的两个 RouteConfig 都可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 2018-01-11
      • 2011-10-02
      相关资源
      最近更新 更多