2

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.