我執行重定向以支持傳統URL。
我的控制器看起來像這樣…
Public Class ThingController
Inherits System.Web.Mvc.Controller
Function Details(ByVal id As String) As ActionResult
Dim RedirectId As Guid
Select Case key
Case "legacyurlone"
RedirectId = New Guid("c564c0c1-c365-4b0c-bc33-fd4eadf0551b")
Case "legacyurltwo"
RedirectId = New Guid("157fa15b-8d5d-4f04-87cc-434f7ae93dfa")
Case Else
RedirectId = Guid.Empty
End Select
If Not RedirectId = Guid.Empty Then
Response.StatusCode = Net.HttpStatusCode.MovedPermanently
Response.RedirectLocation = Url.RouteUrl("IdOnly", New With {.id = RedirectId})
Return Nothing
End If
Dim ThingId As Guid = New Guid(id)
Dim db As New ThingEntities
Dim Model As Thing = ...
Return View(Model)
End Function
...
End Class
現在我想如果我能有兩個途徑和控制器功能,處理起來更乾淨。
這就是我現在選擇的方法,我將Response.StatusCode設置爲301,將Response.RedirectLocation設置爲目標URL – 2008-10-21 01:00:05