0
當約束不滿足,我得到一個404頁,我認爲一旦約束是假的,它會移動到下一個路線。無論如何,有這個去下一個路線,而不是給404錯誤?MVC路由約束給出錯誤時404錯誤
routes.MapRoute(_
name:="rewrites", _
url:="{*permalink}", _
defaults:=New With {.controller = "Pages", .action = "rewrites", .id = UrlParameter.Optional},
constraints:=New With {.permalink = New urlConstraint()} _
)
routes.MapRoute(_
name:="Default", _
url:="{controller}/{action}/{id}", _
defaults:=New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
Public Function Match(httpContext As System.Web.HttpContextBase, route As System.Web.Routing.Route, parameterName As String, values As System.Web.Routing.RouteValueDictionary, routeDirection As System.Web.Routing.RouteDirection) As Boolean Implements System.Web.Routing.IRouteConstraint.Match
If Not String.IsNullOrEmpty(values(parameterName)) Then
If Not values.ContainsKey(parameterName) Then Return False
Dim permalink As String = UCase(values(parameterName).ToString())
Return Db.Routes.Any(Function(a) a.StaticUrl.ToUpper() = permalink)
End If
Return False
End Function