iis 7 - ASP.Net MVC routing legacy URLs passing querystring Ids to controller actions -
We are currently running on IIS6, but are hoping to go to IIS 7.
We are moving an existing web form site to ASP.Net MVC. We have quite a few legacy pages whose new controllers need to be redirected. I came across this article which was interesting:
So I think I can write my own root handler or can redirect me to the controller. Later it smells a bit.
However, I am not sure how to handle query string values from the Legacy URL, which I need to pass the () method shown by my controller. For example:
Legacy URL:
/ artist / visualizer.aspx? ID = 4589
I want to map it:
Artists Controller Show Action
Actually my show takes the name of the action artist, so I want to redirect the user to the Legacy URL / artist / Madonna
Thank you!
Depending on the article that you have mentioned, these steps are needed to:
1-Your legacy handler will have to remove the routes from the query string (in this case this is the artist's ID) The code is to do this:
Public class LegacyHandler: MvcHandler {Private RequestContext RequestContext; Public LegacyHandler (RequestContext RequestContacts): Base (requestContext) {this.requestContext = requestContext; } Safe Override Zero Process Request (HttpContextBase httpContext) {string redirectActionName = ((LegacyRoute) RequestContext.RouteData.Route) .RedirectActionName; Var queryString = requestContext.HttpContext.Request.QueryString; Foreign currency (var key in queryString.AllKeys) {requestContext.RouteData.Values.Add (key, query string [key]); } VirtualPathDataPath = RouteBab.Rout.GateVirtualPath (RequestContact, RedirectionName, RequestContactsRootData.Values); HttpContext.Response.Status = "301 Permanently Enhanced"; HttpContext.Response.AppendHeader ("Location", Path. Virtual Path); 2} You need to add these two routes to the router, where you have the ViewArtist function with the Artist Controller that accepts the id parameter ID type <2 p> route. Add ("Legacy", New Legacy Path ("Artist / Visual Artist. Espacks", "Artist", New Legacy Turnout Hander ()); Routes.MapRoute ("Artist", "Artist / Visual Artist / {ID}", New {Controller = "Artist", verb = "Visual Artist"}});
You can now navigate to a url like: /Artists/ViewArtist.aspx?id=123
and you will be redirected to: / artist / View artist / 123
Comments
Post a Comment