Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Put the "UserHomepage" route first. Then it should do it as what @Felix has explained above. As much as possible, make your default route at the end.</p> <p>But its tricky. You need to add constraints to it because that route will trigger even if what you supplied is the controller name. e.g.</p> <p>if you have <a href="http://yoursite.com/home" rel="nofollow noreferrer">http://yoursite.com/home</a> we expect this to go to your "home/index" as what is defined on the default route. But the UserHomepage route comes first before the default so what we expect will not happen, instead <a href="http://yoursite.com/home" rel="nofollow noreferrer">http://yoursite.com/home</a> will go to "account/viewuser/home" treating home as the id.</p> <p>A solution to this is to define a constraint.</p> <p>What i did is define a constraint class </p> <pre><code>Public Class UserNameConstraint Implements IRouteConstraint Public Function Match(ByVal httpContext As System.Web.HttpContextBase, ByVal route As System.Web.Routing.Route, ByVal parameterName As String, ByVal values As System.Web.Routing.RouteValueDictionary, ByVal routeDirection As System.Web.Routing.RouteDirection) As Boolean Implements System.Web.Routing.IRouteConstraint.Match Dim list As New List(Of String) list.Add("home") 'List of controller names For Each item In list If values("id").ToString() = item Then Return False End If Next Return True End Function End Class </code></pre> <p>After defining the constraint change your route to include the constraint</p> <pre><code> routes.MapRoute( _ "UserHomepage", _ "{id}", _ New With {.controller = "Case", .action = "FriendlyName"}, _ New With {.id= New UserNameConstraint()} _ ) </code></pre> <p>This route now will disregard if the id is listed on the list on the constraint.</p> <p>Thats it. Hope you understand. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload