I am converting an existing classic ASP website to (VB) MVC and I don't want any of the existing URLs to break. I have read many posts (like this one: Routing Classic ASP Requests To .NET - SEO Redirects) about how to do the proper 301 redirect. With the latest MVC release, I've gathered that
Response.RedirectPermanent(objRedirect.new_url, True)
is all that is needed.
I have entered all of my old URLs in a database table with a corresponding column of the new URL. I have added code in my custom 404 page to get the original URL:
Dim strURL As String = Request.RawUrl.Substring(Request.RawUrl.IndexOf("aspxerrorpath=") + 15).ToLower()
so I can look it up in the database. (Interesting sidenote, MSDN's documentation here - Redirect Mode - seems to say that if I set RedirectMode=ResponseRewrite in the CustomErrors section of my web.config, I won't have to worry about doing the above, but when I've tried that, I get IIS errors saying it won't serve an ASP page?!?!?)
The problem I am encountering is that any of my old, Classic ASP URLs that have the same directory as a new MVC route are somehow being partially routed. For example, "/test/default.asp" shows up as "/test/test" in the above strURL variable of my error page.
I do have a route setup for "test":
routes.MapRoute("Test", _
"test/{action}", _
New With {.controller = "test", .action = "index"})
in Global.aspx.vb, but I also have tried every conceivable way to ignore all ASP pages in routes (seemingly to no avail). Here are the attempts I've made (I did see one old - 2008 - post by Phil Haack that said I could only have one of these "catch all" ignore routes, but don't know if that's still valid or not?):
routes.IgnoreRoute("{file}.asp")
routes.Ignore("{resource}.asp/{*pathInfo}")
routes.IgnoreRoute("{resource}.asp/{*pathInfo}")
routes.Add(New Route("{resource}.asp/{*pathInfo}", New StopRoutingHandler()))
and none of them seemed to make any difference (I tried them all one at a time obviously).
This isn't isolated to just one route either - it occurs for any directories that existed on the old site that match a named route on the new site.
Thanks in advance for any and all suggestions you have!
UPDATE: Here are 2 more "issues" I've discovered:
- I am loosing the original querystring. So, if product.asp?id=1 is requested, all I have in the error page is product.asp (any idea how to get at/save the original querystring?)
Another one of my routes looks like this:
routes.MapRoute("IndependentSales", _ "independentsales/{action}", _ New With {.controller = "independentsales", .action = "index"})
and when I request "/resale/default.asp", it goes to "resale/independentsales". WHAT is up with that???