views:

157

answers:

3

Hi everyone!!

I have a page that I want it to have 2 different routes: "/Admin/Schedules" AND "/Schedules"

"/Admin/Schedules" if for admin users and the page will render some admin features and it needs to log in... on the other hand, "/Schedules" is for non-logged users and it will render non-admin features...

But, the page is the same and I specifically need these two routes...

Does anyone know how to do this?

Thanks!!!

A: 

You can do it in your controller instead of the routing. RedirectToAction or RedirectToRoute can help you.

ajma
+1  A: 

you could accomplish this in the controller as ajma said by just having an if condition and a switch statement in a method that checks if the user exist like so:

    if(UserID !=null)
       {

       switch(UserPreference)
       {
           case 1:
                            action = "Schedules"; 

                            top = TypeOfPage.Admin;
                            view = "Schedules";

                            break;
           default:
                            action = "Schedules"; 
                            top = TypeOfPage.Nonuser;
                            view = "Schedules";
                            break;
       }
 }
TStamper
A: 

I have these: App > Controllers > Admin > AdminController and AgendaController

To have this: "/Admin/Agenda/Index" working I had to do this:

routes.MapRoute(
                "AdminAgenda",
                "Admin/{controller}/{action}/{id}",
                new { controller = "Admin", action = "Index", id = "" },
                new { controller = "Agenda" }
               );

This: "/Agenda" also works but I don't know yet... but, that's not my problem right now.

So, for my "Schedules" page, I want to create a new Controller named SchedulesController under App > Controllers > Admin

So, what I need is when a person types "/Admin/Schedules", it will require to be loggedOn, because. But, when a person only types "/Schedules", it will be able to see the page, but with some features out because it is not an admin user.

So, the 2 routes will lead to the same page... how can I do that?

Thanks!!

AndreMiranda