Asp.net mvc 如何设置MVC路由以处理旧ASP经典页面重定向

Asp.net mvc 如何设置MVC路由以处理旧ASP经典页面重定向,asp.net-mvc,asp-classic,routing,Asp.net Mvc,Asp Classic,Routing,我正在将ASP经典网站迁移到ASP.net MVC。 有没有办法将旧流量重定向到新流量? 示例:如何开始: www.mydomain.com/viewpage.asp?pageid=1234 致: 您可能必须在404错误页面中使用response.redirect,并将查询字符串输入映射到所需的新页面。我发现最好的方法是: 使用重定向引擎(例如) 在BeginRequest方法中重定向 我最终使用了#2,因为它对我的项目来说更简单 Sub Application_BeginRequest(By

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

示例:如何开始:

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


您可能必须在404错误页面中使用response.redirect,并将查询字符串输入映射到所需的新页面。我发现最好的方法是:

  • 使用重定向引擎(例如)
  • 在BeginRequest方法中重定向
  • 我最终使用了#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
    
    您也可以使用
    Context.RewritePath
    ,但它不会更改客户端浏览器中的url

    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