Ich denke MVC sieht dies nicht als ein Fehler (d. H. Löst keine Ausnahme), aber es entspricht einfach keiner der Routen, und als solches kann IIS das 404 wie gewohnt behandeln. Um dies in Code zu behandeln, würde ich eine Wildcard-Route am Ende Ihrer Routing-Liste hinzufügen.
Global.asax.vb & hellip;
routes.MapRoute(_
"FileNotFound", _
"{*key}", _
New With {.controller = "FileNotFound", _
.action = "Http404"} _
)
FileNotFoundController.vb & hellip;
Function Http404(ByVal key As String) As ActionResult
Dim RedirectId As Guid
Select Case key
Case "someold/path/andfile.php"
RedirectId = New Guid("68215c26-0abe-4789-968e-0187683409b6")
Case Else
RedirectId = Guid.Empty
End Select
If Not RedirectId = Guid.Empty Then
Response.StatusCode = Net.HttpStatusCode.MovedPermanently
Response.RedirectLocation = Url.RouteUrl("SomeOtherRoute", New With {.id = RedirectId})
Else
Throw New Exception("Unable to resolve route.")
End If
Return Nothing
End Function
Dadurch können Sie die beabsichtigte URL anzeigen und entscheiden, auf welche Ziel-URL sie weitergeleitet werden soll.
Alternativ können Sie eine benutzerdefinierte 404-Handlerseite implementieren und diese direkt in IIS festlegen. Im Code dieser Seite/Controller können Sie die beabsichtigte URL und Weiterleitung als notwendig ansehen.
Verwandte Frage: http://stackoverflow.com/questions/108813/404-http-error-handler-in-asp-net-mvc-rc-5 –