2

I'm working on an MVC3 project and i have to add a login mechanism. I have to use the <authentication> method. I thought that this would automatically redirect users to the login page? But nothing is happening.

I have this in my web.config file:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

But my login controller isn't invoked automatically. What do i have to do to make it work the way i want?

1 Answer 1

6

The user will be redirected to the LogOn page if he attempts to access a protected resource (for example a controller action decorated with the [Authorize] attribute) and he is not authenticated.

If you want to use the LogOn action as your start page then you could update your route setup in Global.asax in order to provide the default controller and action:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }
);

Now when a user navigates to / he will automatically be presented with the logon screen.

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

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.