code_junkie

Returning a 301 Redirect from a Controller Action

Nov 11th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Public Class ThingController
  2. Inherits System.Web.Mvc.Controller
  3.  
  4. Function Details(ByVal id As String) As ActionResult
  5. Dim RedirectId As Guid
  6. Select Case key
  7. Case "legacyurlone"
  8. RedirectId = New Guid("c564c0c1-c365-4b0c-bc33-fd4eadf0551b")
  9. Case "legacyurltwo"
  10. RedirectId = New Guid("157fa15b-8d5d-4f04-87cc-434f7ae93dfa")
  11. Case Else
  12. RedirectId = Guid.Empty
  13. End Select
  14. If Not RedirectId = Guid.Empty Then
  15. Response.StatusCode = Net.HttpStatusCode.MovedPermanently
  16. Response.RedirectLocation = Url.RouteUrl("IdOnly", New With {.id = RedirectId})
  17. Return Nothing
  18. End If
  19. Dim ThingId As Guid = New Guid(id)
  20. Dim db As New ThingEntities
  21. Dim Model As Thing = ...
  22. Return View(Model)
  23. End Function
  24.  
  25. ...
  26.  
  27. End Class
Add Comment
Please, Sign In to add comment