Eduardo Molteni
Eduardo Molteni

Reputation: 39413

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

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

Upvotes: 3

Views: 558

Answers (2)

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

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.

Upvotes: 3

schar
schar

Reputation: 2658

It appears you may have to use response.redirect in the 404 error page and map the query string input to the required new page. Round about way but works

Upvotes: 0

Related Questions