R – How to setup MVC routes to handle old ASP classic pages redirects

asp-classicasp.net-mvcrouting

I'm migrating a ASP classic site to ASP.net MVC.
Is there a way to redirect the old traffic to the new one?

Example: how to go from:

www.mydomain.com/viewpage.asp?pageid=1234

to:

www.mydomain.com/page/1234

Best Answer

Researching the issue I found that the best way was to:

  1. Use a redirect engine (like urlrewriter.net)
  2. Redirect in the BeginRequest method

I ended up using #2 because it more simple for my project

Sub Application_BeginRequest(ByVal sender As Object, _
                                        ByVal e As System.EventArgs)  
   Dim fullOriginalpath As String = Request.Url.ToString.ToLower

   If (fullOriginalpath.Contains("/viewpage.asp?pageid=")) Then
      Context.Response.StatusCode = 301 'issue a permanent redirect'
      Context.Response.Redirect("/page/" + getPageIDFromPath(fullOriginalpath))
    End If

End Sub

You could use Context.RewritePath too, but it does not change the url in the client browser.