In Controllers/AccountController.cs:
public class AccountController : Controller
{
//
// GET: /Account/Login
public ActionResult Login()
{
return View();
}
...
}
In web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" defaultUrl="~/Home/Index" name=".ASPXFORMSAUTH"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
In Views/Account/Login.aspx:
<script runat="server" type="text/C#">
protected void Page_Load(object sender, EventArgs e) {...}
protected void OnAuthenticate(object sender, AuthenticateEventArgs e) {...}
protected void OnLoggedIn(object sender, EventArgs e){...}
protected void OnLoginError(object sender, EventArgs e){...}
</script>
...
<asp:Login ID="login1" runat="server"
DestinationPageUrl="~/Views/Home/Index.aspx"
OnAuthenticate="OnAuthenticate"
OnLoggedIn="OnLoggedIn"
OnLoginError="OnLoginError">
...
<asp:Button ID="loginButton" runat="server" CommandName="Login1" Text="Login" ValidationGroup="login1" TabIndex="4" />
...
</asp:Login>
Page_Load is called, but then OnAuthenticate, OnLoggedIn, and OnLoginError are never called. Why is that?
I am using MVC, and what happens after clicking the “Login” button is I am taken back to the AccountController. This returns the Login.aspx View, so the login page just gets reloaded.
I ended up re-writing everything from scratch, using Razor instead of ASPX.
I don’t know how I could have fixed the issue in this question, and I took a completely different approach.