Nannette Thacker Web Application Development



See all Blog Posts by Nannette.

Nannette Thacker, consultant and owner of Shining Star Services LLC, specializes in development of custom dynamic database driven web applications utilizing technologies. Nannette has been developing ASP sites since 1997. Nannette has written numerous articles on web development techniques and tutorials.

Nannette is the owner and developer of

 Subscribe in a reader

View Nannette  Thacker's profile on LinkedIn

OnLoggingIn Custom Method

When you use the Login control in the toolbox, it generates code that looks like this:

<asp:Login ID="Login1" runat="server">

And from design view, it looks something like this (depending on your background):

When a user then uses the log in control to log into the site, ASP.NET sends them to the ValidateUser function in the MembershipProvider class.

But what if you want to run your own custom code prior to validating the user? You can add your own "OnLoggingIn" method.

Microsoft provides more information on the OnLoggingIn Method and explains that it "Raises the LoggingIn event when a user submits login information but before the authentication takes place." See this article on the Login.LoggingIn Event also. Both articles have some examples of this in use. You might also want to see the Login Control Events section of the ASP.NET Page Life Cycle Overview document.

So in effect, if you are using a Login control and you want to run your custom log in code before the system handles the log in, you may use the "OnLoggingIn" property to access your custom function.

<asp:Login ID="Login2" runat="server" 
Notice I simply added this property to the log in control:

You'll put your Login1_LoggingIn method in your code behind:
Protected Sub Login1_LoggingIn(ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
        ' pre log in code goes here
End Sub

May your dreams be in ASP.NET!

Nannette Thacker


Justin-Josef Angel [MVP] said:


We know how to read MSDN2 and the ASP.Net Quickstars ourselves.

What's the added value of this post?

# January 29, 2008 4:51 PM
Leave a Comment