Forgive my somewhat-lacking ASP.NET knowledge for this question 🙂
Here’s the scenario: I’m playing around in VS2010, I’ve created a new ASP.NET Web Application (under Visual C#, Web templates). Nothing special, just a basic web application. No fancy MVC stuff.
Included in the template-generated solution is a Login page; Account/Login.aspx. On that page, is a Login button; the HTML looks like this:
<p class="submitButton">
<asp:Button ID="LoginButton"
runat="server"
CommandName="Login"
Text="Log In"
ValidationGroup="LoginUserValidationGroup"/>
</p>
Again, nothing fancy. Now, the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Account_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
}
}
Even less fancy. And finally, from web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
So, here is what I can’t quite figure out: when I run the app, I can click the Login button, and the app does something – but where is the code for that something?
Coming from the WPF world (with some background in ASP.NET), my first instinct is to zero-in on CommandName – but a search for anything relating to “Login” turns up dry. My second instinct is to look at the code-behind, but again, it’s pretty sparse and I don’t see anything that looks like it has anything to do with a Login button being clicked.
So where does the “magic” behind this button happen? There has to be something; I feel like I’ve overlooked something that is sitting right in front of my eyes.
If you’re referring to the Default Web Application (not the empty) that comes out of the box with Visual Studio, you’ll notice that login button is inside an
<asp:Login>server control. That’s where the magic is happening. It interfaces with the ASP.NET Membership provider if you look in the web.config, you’ll see references to that.