ASp.Net MVC routing
I am using MVC 2.0 to create my application,my problem i s related to the routing. Actually in my application each user have required seperate subdomain,like www.example.com/user1/ ,www.example.com/user2/ ...etc.the default domain is www.example.com.So how can i make it possible with routing in mvc. i have tried like this,
routes.Add(new Route(
"{id}",
new RouteValueDictionary(
new { controller = "User", action = "login", id = " " }
), new MvcRouteHandler()));
var defaults = new RouteValueDictionary(
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
routes.Add(new Route(
"{controller}/{action}/{id}",
defaults,
new MvcRouteHandler()));
But the problem is that i开发者_Python百科t take deafult (www.example.com) directly to user login page.I want the default page as Home/index and when www.example.com/user1/ it will go to user login page.Is there any way ..pls help me
You could map a specific route for the home page.
routes.MapRoute("home","", new{controller="Home",action="Index"});
routes.MapRoute("users", "{username}/{action}", new { controller = "Users", action = "Login",username="" });
精彩评论