I’m working with ASP.NET MVC 4. When we build a project, they add an AccountController by default. You can create an acoount and log in right away… but after they’ve logged in, try to type http://localhost:port/Account/LogOn. You still stay at the Login page with the login form.
I have tried to redirect the user by using this code:
//
// GET: /Account/LogOn
[AllowAnonymous]
public ActionResult LogOn()
{
if(Membership.GetUser().UserName != null)
RedirectToAction("Index", "Home");
return ContextDependentView();
}
The code works fine until I log out, and then this code no longer works. Please show me the right way to do this.
You don’t have to copy over the rights-chechking code – do write a filter instead and use it multiple times with no code duplication.
In your controller