Asp.Net MVC 默认路由

发布于 2024-08-07 18:53:27 字数 496 浏览 7 评论 0原文

我的默认路线是这样定义的

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美男兮 2024-08-14 18:53:27

最好将其放入家庭控制器中。检查是否已通过身份验证并返回适当的视图。

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

倾听心声的旋律 2024-08-14 18:53:27

我希望他们采用不同的默认路由

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路由实现您想要的目标的限制,但我认为这不是您想要的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文