ASp.Net MVC routing

被刻印的时光 ゝ 提交于 2019-12-25 02:45:00

问题


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 it 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


回答1:


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="" });


来源:https://stackoverflow.com/questions/2786473/asp-net-mvc-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!