Asp.Net MVC 默认路由
我的默认路线是这样定义的
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
但是,如果用户在访问该网站时登录(如果他们上次登录时勾选了“记住我”按钮,则可能会发生这种情况)我希望他们采用不同的默认路线并直接转到登录页面。
这在 global.asax 中是否可能,或者我是否需要在我的家庭控制器中放置一些逻辑以在登录后进行重定向?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好将其放入家庭控制器中。检查是否已通过身份验证并返回适当的视图。
Best to put this in the home controller. A check if authenticated and return the appropriate view.
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.)
可以使用se路由实现您想要的目标的限制,但我认为这不是您想要的。
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.