Authentication in ASP.NET MVC


Q: What controls to show the Login page when you access a authorized-required resource in an MVC application?

A: The web.config

   1: <authentication mode="Forms">

   2:     <forms loginUrl="~/Account/LogOn" timeout="2880" />

   3: </authentication>


For example in your AccountController you have the following.

   1: [Authorize]

   2: public ActionResult ChangePassword()

   3: {

   4:     return View();

   5: }

The [Authorize] attribute says authentication is required when you want to change your password, but it doesn’t specify where to direct you to for the authentication.