问题
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!!!
回答1:
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;
}
}
回答2:
You can do it in your controller instead of the routing. RedirectToAction or RedirectToRoute can help you.
来源:https://stackoverflow.com/questions/492625/problem-with-asp-net-mvc-routing