Asp.Net MVC默认路由 [英] Asp.Net MVC Default Route

查看:145
本文介绍了Asp.Net MVC默认路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的默认路由这样定义

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.

这是可能在Global.asax中或将我需要把一些逻辑,在我家的控制器来重定向如果登录?

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

推荐答案

最好把这个家中的控制器。如果认证的检验,并返回相应的视图。

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

这篇关于Asp.Net MVC默认路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆