Permanent Redirect Legacy Routes for static files in ASP.Net MVC?

I use the following code for my MVC 2 websites.

Up vote 4 down vote favorite share g+ share fb share tw.

Our old ASP.net site stored static images in a sub directory on the root called /images. Our new ASP.net MVC site stores these images in the new layout of /Content/Images I've changed all the pages in the site to cope with the new folder structure, but I'd like to set up Permanent Redirects from the old static images to the new location. Our site is hosted, and I don't have control over IIS, so what is the best approach to solve this?

Asp.net asp. Net-mvc asp. Net-mvc-3 asp.

Net-mvc-routing link|improve this question asked Jan 12 '11 at 2:43Scott Ferguson2,42821126 71% accept rate.

It turns out that my web host did let me have control over IIS, and therefore I was able to use the Url Rewriting module to accomplish my requirements. However, I will leave this question up in case the community provide an answer for those who are in the situation I thought I was in. – Scott Ferguson Jan 18 '11 at 23:25.

I use the following code for my MVC 2 websites: // The legacy route class that exposes a RedirectActionName public class LegacyRoute : Route { public LegacyRoute(string url, string redirectActionName, IRouteHandler routeHandler) : base(url, routeHandler) { RedirectActionName = redirectActionName; Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index"}); // is not actually called } public string RedirectActionName { get; set; } } // The legacy route handler, used for getting the HttpHandler for the request public class LegacyRouteHandler : MvcRouteHandler { protected override IHttpHandler GetHttpHandler(RequestContext requestContext) { requestContext.HttpContext.Response. Write("success"); return new LegacyHandler(requestContext); } } // The legacy HttpHandler that handles the request public class LegacyHandler : MvcHandler { public LegacyHandler(RequestContext requestContext) : base(requestContext) { requestContext.HttpContext.Response. Write("success"); ProcessRequest(requestContext.

HttpContext); } protected override void ProcessRequest(HttpContextBase httpContext) { string redirectActionName = ((LegacyRoute) RequestContext.RouteData. Route). RedirectActionName; var route = new Route(redirectActionName, ((LegacyRoute)RequestContext.RouteData.

Route). Defaults, new MvcRouteHandler()); // Copy all of the querystring parameters and put them within RouteContext.RouteData. Values var values = new Dictionary(); foreach (var s in RequestContext.RouteData.

Values) { values. Add(s. Key, s.

Value); } foreach (var s in httpContext.Request.QueryString. AllKeys) { values. Add(s, httpContext.Request.

QueryStrings); } var data = route. GetVirtualPath(RequestContext, new RouteValueDictionary(values)); httpContext.Response. Status = "301 Moved Permanently"; httpContext.Response.

AppendHeader("Location", "/" + data. VirtualPath + "/"); httpContext.Response.End(); } } Then I simply add legacy routes to my route map: routes. Insert(13, new LegacyRoute("search", "search/{query}", new LegacyRouteHandler())).

Where do you create the . Cs file for the LegacyHandler, MVC3? How will this work to redirect url's as: ~/products.

Aspx? Id=1 – Picflight Feb 21 '11 at 12:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions