繁体   English   中英

如何使用 MVC MapRoute 来匹配不考虑路径的文件扩展名?

[英]How to use MVC MapRoute to match a filename extension w/o regards to the path?

我正在尝试使用 MVC MapRoute 重定向任何具有特定扩展名的文件,无论路径信息是什么 - 如下所示:

www.mywebsite.com/blah.xyz
www.mywebsite.com/whatever/hithere.xyz
www.mywebsite.com/test/morestuff/kittens.xyz
www.mywebsite.com/anything/everything/nothing/testing.xyz
www.mywebsite.com/1/2/3/4/5/6/7/8/9/alphabits.xyz

我创建了一个 routeBuilder,我的 MapRoute 看起来像

routeBuilder.MapRoute("", "{filename}.xyz", new { controller = "Custom", action = "SpecialRedirect" });

我不确定如何将带有 .xyz 扩展名的任何页面/文件请求发送到处理方法,但是,我不确定如何忽略路径的 rest。

有任何想法吗?

看起来他们没有办法做到这一点,所以我求助于其中的一些。

   routeBuilder.MapRoute("", "{filename}.xyz",
        new { controller = "Custom", action = "SpecialRedirect" });
    
routeBuilder.MapRoute("", "{a}/{filename}.xyz",
    new { controller = "Custom", action = "SpecialRedirect" });

routeBuilder.MapRoute("", "{a}/{b}/{filename}.xyz",
    new { controller = "Custom", action = "SpecialRedirect" });

routeBuilder.MapRoute("", "{a}/{b}/{c}/{filename}.xyz",
    new { controller = "Custom", action = "SpecialRedirect" });

routeBuilder.MapRoute("", "{a}/{b}/{c}/{d}/{filename}.xyz",
    new { controller = "Custom", action = "SpecialRedirect" });

routeBuilder.MapRoute("", "{a}/{b}/{c}/{d}/{e}/{filename}.xyz",
    new { controller = "Custom", action = "SpecialRedirect" });

如果有人有更好的方法(这确实有效,但对我来说很难看),请回答。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM