在ASP.NET MVC的MapPageRoute通配符,以支持组织的传统code [英] Wildcards with ASP.NET MVC MapPageRoute to support organizing legacy code

查看:81
本文介绍了在ASP.NET MVC的MapPageRoute通配符,以支持组织的传统code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移现有的ASP.NET网站到一个MVC项目。有迹象表明,我不希望重写,只是还没有几个(60+)的网页,所以我不知道是否有一种方法,我可以:

I'm working on migrating an existing ASP.NET web site into an MVC project. There are several (60+) pages that I don't want to rewrite just yet, and so I'm wondering if there's a way that I can:


  • 将现有的.aspx页面(标记和code隐藏文件)到一个遗产的文件夹在我的MVC结构

  • 设置了路由,以便调用/foo.aspx(没有'遗产')实际上会调用〜/传统/ foo.aspx

实际上,我不想在URL中的遗产,但我也不想MVC解决方案,以饱满的传统的.aspx页面。我承认,这是一个非常小的点,我只是好奇,如果它可以与路由来完成。

Effectively, I don't want "legacy" in the URL, but I also don't want the MVC solution to be full of legacy .aspx pages. I accept that this is a very minor point, I'm just curious if it can be done with Routing.

我知道我可以做的:

routes.MapPageRoute("legacy-foo", "Foo.aspx", "~/Legacy/Foo.aspx"); 

但我不知道是否有办法做到这一点动态(使用MVC路由)?例如:

but I'm wondering if there is a way to do that dynamically (using MVC routes)? eg:

routes.MapPageRoute("legacyroutes", "{filename}.aspx", "~/Legacy/{filename}.aspx"); 

我想的方法之一是使用URL重写模块,但似乎有点多余,如果路线有能力本身这样做的。

I guess one way is to use a URL rewriter module, but that seems a bit redundant if routes is capable of doing this natively.

推荐答案

不知道你还需要这一点,但你可以用肮脏的解决方案解决这个问题:

Not sure if you still need this, but you could solve this with a dirty solution:

使用 HttpContext.Current.Request.MapPath()来获取路由的物理位置,然后遍历所有的aspx文件(和其他任何你想使用的DirectoryInfo / FileInfo的类映射)。然后,您可以动态注册为您的文件替代的路径。

Use HttpContext.Current.Request.MapPath("") to get the physical location of the route, and then loop over all aspx files (and anything else you want to map) using the DirectoryInfo/FileInfo classes. You can then dynamically register alternative paths for your files.

我已经做了原型,它似乎是工作,但当然,魔鬼总是在细节中。

I've done a prototype and it appears to be working, although of course, the devil is always in the details.

干杯,

这篇关于在ASP.NET MVC的MapPageRoute通配符,以支持组织的传统code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆