Search code examples
c#.netasp.net-mvcloggingasp.net-mvc-routing

Asp.Net MVC Default Route


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?


Solution

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