New ASP.NET Web Application: There's a Login button that does something, but where does the magic happen?

Forgive my somewhat missing ASP.NET knowledge for this question :)

Here's the scenario: I play in VS2010, I created a new ASP.NET Web Application (in Visual C #, web templates). Nothing special, just a basic web application. No fancy MVC materials.

The template created by the template includes a login page; Account/Login.aspx . There is a "Login" button on this page; HTML looks like this:

 <p class="submitButton"> <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/> </p> 

Again, nothing out of the ordinary. Now the code is 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 imagination. And finally from web.config:

  <authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880"/> </authentication> 

So here is what I can’t understand. : when I start the application, I can click the "Login" button, and the application does something, but where is the code for something?

From the world of WPF (with some experience with ASP.NET), my first instinct is to reset CommandName , but searching for anything related to “Login” becomes dry. My second instinct is to look at the code, but again, it’s pretty sparse, and I don’t see anything like it having anything to do with clicking the Login button.

So where does the “magic” behind this button happen? There must be something; I feel that I am losing sight of what is sitting right in front of my eyes.

+4
source share
5 answers

If you are referencing a default web application (not empty) that leaves the box using Visual Studio, you will notice that the login button is inside <asp:Login> . Where magic happens. It interacts with the ASP.NET membership provider, if you look in the web.config file, you will see links to it.

+7
source

The page is sent back. but the event handler is not connected, so it does nothing. I know how to do this with the code that is generated when a button is added. The button generates JavaScript code that calls a function to return the page.

You need to add an event handler. The easiest way is to simply double-click the button in the form designer and create the code for you.

+2
source

Button is a server-side control - this causes it to be sent back when clicked.

If you look at the source of the page, you will see a call to __dopostback , a javascript function that sends the page back to itself.

At this point, the page reloads, which is probably what you see.

+1
source

Nothing happens (except postback to the server), CommandName="Login is the template code for you. Does nothing without OnCommand="CommandBtn_Click" and the associated event handler in code-behind

+1
source

I feel that you need the source code. You are interested in how the provider logs in. Nuts and bolts, so to speak ...

http://weblogs.asp.net/scottgu/archive/2006/04/13/442772.aspx

0
source

All Articles