Last post May 10, 2014 10:15 AM by markfitzme
May 08, 2014 02:33 PM|DowntownJoe|LINK
I am creating a cookie with LastLoginDate info in it:
protected void Login1_LoggedIn(object sender, EventArgs e)
Response.Cookies["LastLoginDate:" + Login1.UserName].Value = Membership.GetUser(Login1.UserName).LastLoginDate.ToString();
Response.Cookies["LastLoginDate:" + Login1.UserName].Expires = DateTime.Now.AddDays(30);
But I want to use the HttpContext.Current.User.Identity.Name instead of the text from the login control, but the context is not authenticated and there is no name. I use the Context elsewhere my program to display the cookie info (on the master page), and
that works, when does the context get set? I would have thought it was before the LoggedIn event?
May 08, 2014 03:11 PM|AidyF|LINK
In the past I've seen the identity not get set until the next request as it is cookie-based. If you always direct your users to a certain page after they log in you could put the code there. However if the Login1.Username property is the same as the username
then is it much of an issue?
May 09, 2014 05:48 PM|DowntownJoe|LINK
the "issue" is that Login1.UserName is userspace while HttpContext.Current.User.Identity.Name is serverspace.
It's not much of an issue, but it seems like it would be "safer" to query the server for a piece of information.
May 10, 2014 10:15 AM|markfitzme|LINK
Not sure what you mean by userspace. Login1.UserName is serverside and within the same context of the HttpContext.Current. Both are scoped to the same request context but one is scoped to a particular page instance.
Are you using forms authentication? If so, create a formsauthenticationticket. You can do this with your own user system and not have to use the asp.net membership.
This will create an encrypted ticket that contains the information necessary to populate the current identity information.