Custom MVC and ActionLinks Routes

We are working with the asp.net mvc application, which is used by several clients. We need URLs to include a friendly client name. For example:

domain.com/clientName/controller/action/id

The following shows that this works when it comes to routing, but "clientName" is not generated correctly for action reference helpers.

_routes.MapRoute("DefaultRoute",
                "{clientName}/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = string.Empty },
                new { clientName = @"[\w-]+" });

We would like to continue using the Html.ActionLink Helper methods, but it does not include the clientName name in the generated link. Should we write our own helpers in this scenario or is there an alternative approach?

Has anyone else created an application with this type of routing? Any suggestions would be appreciated!

+5
3

, , RouteLink . , . , - :

routes.MapRoute("Base", 
                string.Empty,
                new { controller = "Home", 
                action = "Index", 
                id = string.Empty });

DefaultRoute, ActionLink, . .

0

, ActionLink, Darin, URL-, :

http://host/Home/action?clientName=someClient

URL , . RouteLink, :

<%= Html.RouteLink("some text", "DefaultRoute", new { clientName = "someclient" })%>
+11

:

<%= Html.ActionLink("some text", "action", new { clientName = "someclient" })%>

:

http://host/someclient/Home/action

:

_routes.MapRoute("DefaultRoute",
    "{clientName}/{controller}/{action}/{id}",
    new { 
        controller = "Home", 
        action = "Index", 
        id = string.Empty, 
        clientName = "defaultClient" },
    new { clientName = @"[\w-]+" });
+7

All Articles