tags:

views:

129

answers:

1

Hi

I want to do the following:

The user should have his own sub site on my web site. Therefor I've added a new route:

routes.MapRoute(
    "ShopEntered",
    "{username}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

When the site gets called for the first time I want to store the username value in the session and then bind the session value to the username part of the route, so that when I call Url.Action or Html.ActionLink I don't have to set it every time manualy.

Does anyone know how I could realize this?

A: 

The easiest way would probably be to write your own helper methods and use these instead of Html.ActionLink and Url.Action. For example:

public static class UserUrlExtensions
{
    // Create whichever overloads you want
    public static string UserActionLink(this HtmlHelper helper, string linkText, RouteValueCollection routeValues)
    {
        // Get whatever value it is you want from the current context
        routeValues["User"] = helper.ViewContext.HttpContext.Current.User.Identity.Name;

        return helper.ActionLink(linkText, routeValues);
    }
}

I don't guarantee that it will work without modification, but you get the idea of how to do the work...

Tomas Lycken