I've got a registration page that automatically logs the user in when they register. At first I just had 1 line of code to log the user in:
Member.AddMemberToCache(member);
But after testing I noticed that this method causes the <asp:LoginName /> control to display the users UniqueID instead of their LoginName. My way around the problem was to add FormsAuthentication.SetAuthCookie() under the above. So now my code looks like:
Thanks for the reply Lee, but that didn't fix my problem.
The AuthCookie is being set by AddMemberToCache, but the username in the cookie (Page.User.Identity.Name) is being set to member.UniqueID instead of member.LoginName
Programmatically login user with Member.AddMemberToCache()?
I've got a registration page that automatically logs the user in when they register.
At first I just had 1 line of code to log the user in:
Member.AddMemberToCache(member);
But after testing I noticed that this method causes the <asp:LoginName /> control to display the users UniqueID instead of their LoginName.
My way around the problem was to add FormsAuthentication.SetAuthCookie() under the above. So now my code looks like:
Member.AddMemberToCache(member);
FormsAuthentication.SetAuthCookie(member.LoginName, false);
Is this the correct way to log a user in programatically in umbraco? It feels a bit hacky to me.
I'm using umbraco 4.0.4.1
Thanks,
Jason
Hi Jason,
There is an overload method for "AddMemberToCache", that sets the AuthCookie too:
As far as I can tell, the TimeSpan isn't actually used in setting the expiration of the cookie - guess its a place-holder for future use?
Cheers, Lee.
Thanks for the reply Lee, but that didn't fix my problem.
The AuthCookie is being set by AddMemberToCache, but the username in the cookie (Page.User.Identity.Name) is being set to member.UniqueID instead of member.LoginName
You can test it with the following:
Cheers,
Jason
Hi Jason,
Sorry, just re-read your original post. Yes, the workaround is the way you first suggested - setting the AuthCookie manually.
If you think that functionality should be changed, you could raise a ticket on CodePlex?
Cheers, Lee.
is working on a reply...