views:

72

answers:

2

Say I have 3 versions of a website: A, B and C. I want my urls to be of the form:

{siteType}/{controller}/{action}/{id}

where siteType equals a, b or c.

When the user is in the A version of the website, then they should stay there; therefore all generated urls should have a siteType of a. Similarly for B and C.

I don't want to have to explicitly specify the siteType when generating urls - I want it generated automatically. Furthermore, the siteType parameter will only ever be used in one place - the overrided RenderView method in a base controller class - which will use the siteType parameter to pick out the correct view, css etc for that version of the website. I therefore have no interest in the siteType appearing as an argument to my actions. Only the RenderView method requires access to it.

What is the best way to achieve this?

A: 
Hurricanepkt
Yes, this solves the problem of getting the correct view, but it does not solve the problem of having the siteType ("a") automatically added to each url.
darasd
+1  A: 

We have almost the same with the site language (snippet from our global.asax.cs):

routes.MapRoute(
            "DefaultLanguage",
            "{lang}/{controller}/{action}/{id}",
            new { lang = "de-CH", controller = "Home", action = "Index", id = "" }
        );

Whenever no language is set the language will be set to swiss-german in our case.

Any actionlink will have the language code automatically from the current site. So we don't have to specify any language on Actionlinks.

Changing the siteType is simple, just add routeValues to your actionlink. e.g.

 <%= Html.ActionLink("Linktext", "Action", "Controller", new { siteType = "b" } %>
griti
Yes, but the point is that I don't want to have to add siteType to every ActionLink or to any other url that is generated. Since it is done everywhere, I should be able to have it added automatically in a single place.
darasd
you don't have to add siteType to every url by "hand". Set it once in default routine and it will be added. If you would like to switch between the siteTypes, then you have to add siteType to that action link.All my links are like: <%= Html.ActionLink("Linktext", "Action", "Controller" %> except the one that is switching the language.ActionLink renders the link and adds siteType automatically to something like:<a href="a/Home/About">Linktext</a>
griti
You know, I think you're right! It appears to be added automatically, and to take the current url's value rather than the default if not added explicitly to, for instance, an ActionLink.
darasd