if (Membership.GetUser() != null)
-
Hi, I can't understand, why this line is not working:
if (Membership.GetUser() != null) Session.Add("current_user", Membership.GetUser().UserName);
I used this code in my another program, and it works pretty good, but not in my new program. It is just never "true", even when the user is logging in. Do you know what's wrong? thanks -
Hi, I can't understand, why this line is not working:
if (Membership.GetUser() != null) Session.Add("current_user", Membership.GetUser().UserName);
I used this code in my another program, and it works pretty good, but not in my new program. It is just never "true", even when the user is logging in. Do you know what's wrong? thanks1. Membership.GetUser() will only work for an authenticated user. Otherwise, it's going to return null. To verify you're dealing with an authenticated request call "User.Identity.IsAuthenticated" on the page. If you've got an authenticated request, but Membership.GetUser() is still returning null, then that means the username associated with the authenticated user can't be found in the Membership datasource. Verify the username of the authenticated user with "User.Identity.Name". 2. If you're calling one of the Membership.GetUser() overloads which takes the username and it's returning null, then that user doesn't exist in the Membership datasource (or we've got a bug). One way to easily verify this is to try a Membership.CreateUser() with the same username. If this doesn't throw an error because of a duplicate user, then you know the user never existed in the first place. 3. Membership.GetUser() should have never worked for an anonymous user. No support was built into Membership for handling this case. Hope this helps.
SSK. Anyone who says sunshine brings happiness has never danced in the rain.
-
1. Membership.GetUser() will only work for an authenticated user. Otherwise, it's going to return null. To verify you're dealing with an authenticated request call "User.Identity.IsAuthenticated" on the page. If you've got an authenticated request, but Membership.GetUser() is still returning null, then that means the username associated with the authenticated user can't be found in the Membership datasource. Verify the username of the authenticated user with "User.Identity.Name". 2. If you're calling one of the Membership.GetUser() overloads which takes the username and it's returning null, then that user doesn't exist in the Membership datasource (or we've got a bug). One way to easily verify this is to try a Membership.CreateUser() with the same username. If this doesn't throw an error because of a duplicate user, then you know the user never existed in the first place. 3. Membership.GetUser() should have never worked for an anonymous user. No support was built into Membership for handling this case. Hope this helps.
SSK. Anyone who says sunshine brings happiness has never danced in the rain.
Exactly copied from http://forums.asp.net/p/939408/1170831.aspx[^]
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Exactly copied from http://forums.asp.net/p/939408/1170831.aspx[^]
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
N a v a n e e t h wrote:
Exactly copied from http://forums.asp.net/p/939408/1170831.aspx\[^\]
Probably not. I see the following lines are different though: Source:
Thanks, Mark This posting is provided "AS IS" with no warranties, and confers no rights.
Destination:SSK.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson