开发者

Is it possible to obtain ASP.NET membership user name after FormsAuth.SignIn?

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).


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜