Asp.Net MVC Default Route

ぃ、小莉子 提交于 2019-12-12 20:22:25

问题


I have my default route defined like this

routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

However if the user is logged in when they visit the site (This can happen if they ticked the remember me button last time the logged in) I want them to take a different default route and go straight to the logged in page.

Is this possible in global.asax or will I need to put some logic in my home controller to redirect if logged in?


回答1:


Best to put this in the home controller. A check if authenticated and return the appropriate view.




回答2:


I want them to take a different default route
Routing in ASP.NET MVC is about routing URLs to action methods on controllers, not about routing users to places in your web site depending on the current circumstances. (Think of routing as a static thing, whereas the rest (authorization, redirection, etc) is only applicable to the current session.)

It is possible to use Routing Constraints to achieve what you want, but I don't think that's what you want.



来源:https://stackoverflow.com/questions/1558902/asp-net-mvc-default-route

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