views:

194

answers:

2

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
A: 

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

schar
Yes, this could work too.
Eduardo Molteni
+2  A: 

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.

Eduardo Molteni