如何设置MVC路由来处理旧的ASP经典页面重定向

时间:2020-12-19 23:19:42

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

我正在将ASP经典网站迁移到ASP.net MVC。有没有办法将旧流量重定向到新流量?

Example: how to go from:

示例:如何从:

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

to:

www.mydomain.com/page/1234

2 个解决方案

#1


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

研究这个问题我发现最好的方法是:

  1. Use a redirect engine (like urlrewriter.net)
  2. 使用重定向引擎(如urlrewriter.net)

  3. Redirect in the BeginRequest method
  4. 在BeginRequest方法中重定向

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

我最终使用了#2,因为它对我的项目来说更简单

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.

您也可以使用Context.RewritePath,但它不会更改客户端浏览器中的URL。

#2


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

看来您可能必须在404错误页面中使用response.redirect并将查询字符串输入映射到所需的新页面。绕道而行,但有效

#1


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

研究这个问题我发现最好的方法是:

  1. Use a redirect engine (like urlrewriter.net)
  2. 使用重定向引擎(如urlrewriter.net)

  3. Redirect in the BeginRequest method
  4. 在BeginRequest方法中重定向

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

我最终使用了#2,因为它对我的项目来说更简单

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.

您也可以使用Context.RewritePath,但它不会更改客户端浏览器中的URL。

#2


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

看来您可能必须在404错误页面中使用response.redirect并将查询字符串输入映射到所需的新页面。绕道而行,但有效