Problem with ASP.NET MVC routing

∥☆過路亽.° 提交于 2019-12-11 17:25:40

问题


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

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