Click here to Skip to main content
15,881,801 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)
See more:
hi all,,,,
I have one doubt on asp.net mvc 3 routing..Iam doing a project in mvc3.In my application there is an admin side and also public user side..
I have a controller that is adminController to login the admin..In the adminController there is two action methods for login and home.So the url look like
www.mySite.com/admin/login

www.mySite.com/admin/home

I have created another folder Admin in the controller folder only for accessing administrators and created ManageMembersController in the Admin folder..and the url should look like

www.mySite.com/admin/ManageMembers/list

I have written the custom routing in the global asax file..
routes.MapRoute(
                           "Admin", // Route name
                           "Admin/{controller}/{action}/{data}", // URL with parameters

                           new
                           {
                               controller = "/Admin/ManageMembers",
                               action = "list",
                               data = UrlParameter.Optional
                           } // Parameter defaults
                       );
            routes.MapRoute(
               "admin_default", // Route name
               "admin/{action}/{id}", // URL with parameters
               new { controller = "admin", action = "login", id = UrlParameter.Optional } // Parameter defaults
           );
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Pub", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );




My problem is that when iam trying to www.mySite.com/admin/login I got an error
'The resource cannot be found.'
but the other routing worked properly..
that is www.mySite.com/admin/ManageMembers/list it redirected to the ManageMembersController

My requirement is to redirect to Controller/adminController.cs when the url is www.mysite.com/admin/..
and it must redirect to Controller/Admin/ManageMembers.cs when the url is www.mySite.com/Admin/ManageMembers/..
I need your suggestions...


Thank you Devguys...
Posted
Comments
justinonday 9-Feb-11 6:59am    
good luck .

To have two different controllers with the same name, you'll probably need to organize them into separate areas[^]. As far as I know, you'll then be able to specify the corresponding area for each controller in the routing with something like this:

C#
routes.MapRoute(
     "Default",
     "{area}/{controller}/{action}/{id}",
     new { area = "YourArea", controller = "Admin", action = "List", id = UrlParameter.Optional }
);


etc...

I hope this is helpful.
Phil
 
Share this answer
 
v2
how to run if you have multi subfolder?
Ex: Admin/Component/ComUser/User/
Admin/Component/ComMenu/Menu/
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900