Login event handler in 2.0

K

kpg*

Hi all,

asp.net 2.0

I'm using the login control with no frills to authenticate
users.

I want to add a value to the user's profile when the user
successfully logs in, but I want to do this only once,
and I want to do it each time the user logs in (because
it may change over time).

The login control has a 'LoggedIn' event, but the user is
not flagged as authenticated at this point and the user's
profile does not yet exist.

It seems the earliest that the profile does exist is on the
page that is loaded after the user logs in, but this page can
be loaded many times by authenticated users that are not
necessarily coming from the login page.

I'm looking for an event on the login page that lets know
that the user successfully loggedin (I'm assuming that's
the loggedin event) AND allows access to the user's profile.

I can think of other several ways to get this done but none
are as clean.

I could set a session variable indicating I am coming from the
login page and inspect this each time the login destination page
is loaded.

I could set a default profile value that indicates if has not
been set and only set it in that case (but there is a problem
with this method - the value will change over time so I would
have to clear it when the user logs out - an event I won't
always know about)

I could use the loggedIn event handler and load the profile myself.
So far this is the most attractive solution since it keeps the
login code all in one place.

I'm just a little surprised that the user object has not been
initialized properly in the loggedin event of the login control

kpg
 
K

kpg*

Well, this works:

Protected Sub Login1_LoggedIn(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Login1.LoggedIn

Dim p As ProfileCommon = _
CType(ProfileBase.Create(Login1.UserName), ProfileCommon)

p.myValue = "somevalue based on something"

p.Save()


End Sub
 
E

Eliyahu Goldin

Scott Guthrie explained the problem and offered a workaround to get to the
user roles. See if it is good for profiles too:

The authentication principal won't get set until the next request to the
web-server. But you can use the "UserName" property on the Usercontrol
within the LoggedIn event to identify the user.

You can then use the Role APIs and pass the user name to retrieve their role
information.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top