Monday, March 26, 2012

How do I determine if user is logged in?

I want only authenticated users to save some stuff, so if a user is not logged in, I show a modalpopup to let the user log in:

if (User.Identity.IsAuthenticated)
this.SaveStuff();
else
this.ModalPopupExtender1.Show();

SaveStuff()

{

if(User.Identity.IsAuthenticated)

... save stuff

}


When the user then is logged in, I call the SaveStuff-method, but since the page is not reloaded (I guess), I cannot use User.Identity.IsAuthenticated or Membership.GetUser() to determine if user is logged in. How do I determine if the user is logged when calling the method from the modalpopup

can you access

Context.User.Identity.IsAuthenticated? (or put this value in a cookie, then reference the cookie?)


I can access the above, but it returns false even if the user is loggedin when handling the modalpopup. If I refresh the page, it returnstrue. I need to know the provideruserkey of the membershipuser who hasbeen logged in. Would it be safe to put that in a cookie?

No comments:

Post a Comment