I'm having trouble with the Membership.GetUser() function. I have created a user and can log in via the login function. Initially, I return the username of the validated user (user@email.com). However, when I do a postback or visit any other section,
the Membership.GetUser() function returns null.
I have verifed that the user and userId exists in aspnet_Membership, aspnet_Roles and aspnet_UsersInRoles in the SQLServer 2008 DB.
Has anyone ran into anything like this before? Thanks for your help.
If all you need is the username, then don't waste a trip to the database -- just call
User.Identity.Name. But this might be empty which would explain why the call to membership returns null. But knowing if User.Identity.Name is empty of not will help diagnose the problem.
Thanks BrockAllen. Upon further investigation, I found that the .ASPXAUTH cookie is not being set for certain users, but is being set for other users. I don't know how the user is being authenticated, but yet not receiving the .aspxauth cookie.
FormsAuthentication.RedirectFromLoginPage(UserID.Text, CheckBox1.Checked)
or
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet)
or
FormsAuthentication.RedirectFromLoginPage(UserID.text, true)
This will set .ASPXAUTH value and will redirect to target page or default page.
No4theLizard
0 Points
3 Posts
Membership GetUser() Inconsistent Results
Dec 15, 2012 05:11 PM|LINK
Hi -
I'm having trouble with the Membership.GetUser() function. I have created a user and can log in via the login function. Initially, I return the username of the validated user (user@email.com). However, when I do a postback or visit any other section, the Membership.GetUser() function returns null.
I have verifed that the user and userId exists in aspnet_Membership, aspnet_Roles and aspnet_UsersInRoles in the SQLServer 2008 DB.
Has anyone ran into anything like this before? Thanks for your help.
Tim
BrockAllen
All-Star
27502 Points
4895 Posts
MVP
Re: Membership GetUser() Inconsistent Results
Dec 15, 2012 06:34 PM|LINK
If all you need is the username, then don't waste a trip to the database -- just call User.Identity.Name. But this might be empty which would explain why the call to membership returns null. But knowing if User.Identity.Name is empty of not will help diagnose the problem.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
No4theLizard
0 Points
3 Posts
Re: Membership GetUser() Inconsistent Results
Dec 15, 2012 06:47 PM|LINK
Thanks BrockAllen. Upon further investigation, I found that the .ASPXAUTH cookie is not being set for certain users, but is being set for other users. I don't know how the user is being authenticated, but yet not receiving the .aspxauth cookie.
No4theLizard
0 Points
3 Posts
Re: Membership GetUser() Inconsistent Results
Dec 15, 2012 09:41 PM|LINK
Ah - Another programmer had placed a logout function deep withing a Control. Thanks anyways!
oned_gk
All-Star
31237 Points
6384 Posts
Re: Membership GetUser() Inconsistent Results
Dec 16, 2012 12:04 AM|LINK
If you get right user in login page then
This will set .ASPXAUTH value and will redirect to target page or default page.