473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem handling Login control Authenticate event

I am starting a rewrite of an existing Classic ASP web site in ASP.NET 2.0.
The existing ASP application has several types of users, each with a separate
login process (separate login page, separate DB tables, etc). For one of
these user types, the current application has an additional input field
required for login… they have a username, password, and another “location
code” field. Please don’t make me explain or justify this… the mandate is
for the new ASP.NET 2.0 site not to require users to log in any differently.

I concatenate the existing username with the “location code”, with a
delimiter character between them. This way I can transition the existing
logins to the aspnet_DB schema that uses the normal username & password
fields. Users who input the additional “location code” field will not know
it, but their username will actually be the form of “current username +
delimiter + location code”.

I have converted the built-in Login control to use a Template, and have the
means to show/hide the extra textbox. I am handling the Login control’s
Authenticate event (code below), and when the extra input field is submitted
I concatenate the username with the location code, passing these to
Membership.ValidateUser(). This seems to work fine, it returns true and the
next call to FormsAuthentication.RedirectFromLoginPage() works, and the login
seems to work (access is granted to appropriate pages based on web.config,
LoginStatus control displays correctly, etc.)

However, for the users where this concatenation of the two input field
values is executed, the login is somehow not really complete. In these
cases, Membership.GetUser() returns null, and the LoginName control displays
only the username entered in the default input field, not the full string
that I build with the concatenation of the extra “location code” input field.

For user types where the extra field is not present and the concatenation is
not done, Membership.GetUser() returns the correct user object.

What am I missing? Is there some other event I need to handle, or method I
need to call? In the .NET 2.0 doc files, “about Membership class” the
Example code only references Membership.ValidateUser() and
FormsAuthentication.RedirectFromLoginPage() - though this is not handling the
Authenticate event, but is just a traditional login with textboxes, not the
Login control.

Thanks in advance!!

CODE:
Protected Sub MyLogin_Authenticate(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.AuthenticateEventArgs) Handles MyLogin.Authenticate

Dim username, password, location As String

username = MyLogin.UserName
password = MyLogin.Password

' concat location with username for special login,
' allows them to log in the same way they always have,
' while allowing us to use Membership API based on username & password
If m_LoginUserType = LoginType.Special Then
location = DirectCast(MyLogin.FindControl("Location"), TextBox).Text.Trim()
If location.Length > 0 Then
username = username & "~" & location
End If
End If

e.Authenticated = Membership.ValidateUser(username, password)

If e.Authenticated Then
FormsAuthentication.RedirectFromLoginPage(username , False)
End If

End Sub
Feb 7 '06 #1
1 4503
I seem to have found my own solution... I'm posting in case anyone else will
find this helpful. I added an event handler for the Login control LoggingIn
event. In this handler method I directly modify the Login control UserName
property when the login is my special case, doing the concatenation of the
additional input field with the UserName. This way, when the Authenticate
event fires next, the value has already been modified as I need it. Now,
everything works, including Membership.GetUser() returning a valid object.

There is definitely something about the way I was doing it before that is
not sufficient... the same two method calls - Membership.ValidateUser() and
FormsAuthentication.RedirectFromLoginPage() - ARE sufficient to do everything
on a regular ASPX page with textboxes and a button click event, but NOT when
you just handle the Login control Authenticate event. I also have a need to
accept a simple HTML form post to allow a login from a web page outside my
new ASP.NET app (still in same web domain). For this I use the same two
method calls and everything works fine. But with the Login control, despite
my Authenticate code shown in my post above, there was still something going
on under the hood resulting in a partially incomplete login (see above).
"EricRybarczyk" wrote:
What am I missing? Is there some other event I need to handle, or method I
need to call? In the .NET 2.0 doc files, “about Membership class” the
Example code only references Membership.ValidateUser() and
FormsAuthentication.RedirectFromLoginPage() - though this is not handling the
Authenticate event, but is just a traditional login with textboxes, not the
Login control.


Feb 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
3
by: I am Sam | last post by:
Please help. I'm dying here and pulling out the last few remaining elements of my hair over this. I have built a form that will identify and authenticate users. I keep getting the following...
2
by: ad | last post by:
I use Login control's Authenticate event to authenticate use. I find that different users can use the same ID to login in the same time. How can I restrict that the some ID can only login once in...
4
by: ad | last post by:
I use Login control to authenticate use. How to get the list of user ID who have login in?
3
by: Brian Henry | last post by:
I have an existing user managment system that has been in our asp.net 1.1 app for a couple years now, all the user managment is done through an application that is a win form, and stored in SQL...
1
by: leslie_tighe | last post by:
Hello, I have webservice created with Axis 1.2.1 and that I am trying to consuming in .NET (VB) using the Microsoft provided tools. While I am able to consume methods on the service that return...
3
by: Bruce | last post by:
I just started the design of an ASP.NET application which accesses one of our custom web services to provide user authentication, among other purposes. I created a log-in page (code below),...
5
by: Afshar | last post by:
Hi everybody there, I have a special Login page that wants users to enter 3 passwords rather than a single password. But can't do it with Login control. I tried following scenarios: 1. Put an...
10
by: SAL | last post by:
Hello, I'm still having trouble getting my app to authenticate correctly. I have read the tips at: http://www.devhood.com/messages/message_view-2.aspx?thread_id=72204 and am still having...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.