问题ASP.NET MVC路由 [英] Problem with ASP.NET MVC routing
问题描述
我有我希望它有2个不同的路线的页面:/管理/调度和/时间表
I have a page that I want it to have 2 different routes: "/Admin/Schedules" AND "/Schedules"
/管理/调度如果管理员用户和页面会令一些管理功能,它需要登录...在另一方面,/时间表对于非登录用户,它会呈现非-admin功能...
"/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?
谢谢!
推荐答案
您可以在控制器ajma表示通过,如果只是有一个完成这个条件,如用户有像这样的检查方法的switch语句:
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;
}
}
这篇关于问题ASP.NET MVC路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!