470,596 Members | 1,487 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

Login event handler in 2.0

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
Nov 8 '07 #1
2 1656
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
Nov 8 '07 #2
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
"kpg*" <no@spam.comwrote in message
news:Xn*******************************@207.46.248. 16...
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


Nov 8 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by EricRybarczyk | last post: by
1 post views Thread by Daniel Friend | last post: by
9 posts views Thread by ad | last post: by
5 posts views Thread by Afshar | last post: by
1 post views Thread by JJ | last post: by
3 posts views Thread by =?Utf-8?B?TWFyY0c=?= | last post: by
10 posts views Thread by =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post: by
3 posts views Thread by =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.