开发者

ASP.Net MVC - Trapping certain URL's to do 301 Redirect

I am moving from an old site design to a new design with new URL's.

All previous page names were static files called PageXX.html, PageX.html, Index.html - where X is a number.

My site is now dynamic but I want to trap for those 3 incoming url's and then try and redirect to a certain new page (301 Redirect) else send them to the home page.

Do I do all of this in Global.asax or do I just trap those Url's in Global.asax and then route it to a Action and do a 301 Redirect i开发者_运维问答n the Action?

Any code examples would help a lot!

Thanks

EDIT: I think what needs to be done is trap the routes in Global.asax and then send them to a Action which will work out where to send the user ie. a similar page on the new site else I will send to the home page.


That's right, just do it in your routes configuration (usually in global.asax). You can set these up as static special cases.

routes.MapRoute("Page3", 
            "SomeURL/Page3.html",
            new { 
                  controller = "SomeController",
                  action = "SomeAction",
                  page = "2"
                });


For PageXX.html, PageX.html, Index.html pages you can do regular expression based matching too. That will allow you to maintain the whole thing with a single route mapping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜