views:

82

answers:

3

I have some code that is accessing Membership.GetUser() to get the current logged in user.

This works fine until I try to access it immediately after logging in with FormsAuth.SignIn(userName, false);

However I noticed that neither Membership.GetUser() nor User.Identity.Name is updated with the newly logged in user until a new request (I assume its reading directly from the Request cookies).

This however kind of screws up my logic that accesses Membership.GetUser() becasue it introduces a special case.

Question: is there a way to read the current logged in user with ASP.NET membership immediately after logging in. Or will I have to introduce my own abstraction layer to allow me to 'set' a user as being logged in ? (This is in an AJAX request - so i'd rather not do a redirect).

+1  A: 

This may not help you because it is still a special case but you could use Membership.GetUser(username). This will return the MembershipUser object for the newly created user even though they won't technically be logged in until after the next request and the forms auth cookie is set.

Jeff Widmer
i think i'm going to have to do this
Simon_Weaver
A: 

Is pulling the cookie out of the response and using FormsAuthentication to extract the ticket an option?

Sky Sanders
A: 
void OnLoggedIn(object sender, EventArgs e)
{
    SiteSpecificUserLoggingMethod(Login1.UserName);
}

Use the Login1.UserName, from the Login Control it self it will allow you to access the user name early before the next request.

Dr.H

related questions