I tried to use profiles, and save some profile manually (myProfile.save())..etc
I couldn't find a solution. Membership.GetUser() returns null all the time. No matter what!
Also, User.Identity.Name; is empty as well (
I mean even after successful authentication).
As mentioned earlier, on my very system I downloaded another app (mentioned above) and on this one app
User.Identity.Name; returns the right user name and
Membership.GetUser() doesn't return null but the expected User object ...
Well, I'm no longer sure it works... actually it does take some time for Membership.GetUser() to work correctly. I have to click here and there than comeback to the page where I check whether the successfuly logged-in User is "recognized" as such. So it
is only after few clicks that Membership.GetUser() returns the right value (and no longer this bloody null value).
Eureka! I think I've figured out what my problem was. In the end, my web app was not actually denying access (and hence, was in anonymous mode rather than authenticated).
Specifically, in my web.config snippets above, where I set the local config for the "secure/" sub-section of my sebsite, this was incorrect. It was correct on my local machine, but on my public server the web app is actually sitting in a folder called "prototype"
under the web root. So, that setting had to be changed to "prototype/secure/" and it started working.
Alphonso, my guess is that your problem will also turn out to be something related to your configuration.
I think in LoggedIn event the httpcontext doesn't refresh itself because you cannot get the user identity calling by membership.getuser() or httpcontext.current.user.identity.name or system.security.threading.thread.currentprincipal.identity.name all these
return null however when you are passed into destination page you can get the user information.
there is a problem with the logged in event while refreshing user httpcontext...
This is "by design". The initial request to the page is anonymous and an auth cookie is already set for this before the event is triggered. In the page response, an authenticated ticket cookie will be sent to the browser and subsequest page requests will
include this cookie so that you'll have an authenticated user.
A workaround is to use the Login control to get the username. For example, "Login1.UserName".
Thanks,
Mark
Thanks,
Mark
This posting is provided "AS IS" with no warranties, and confers no rights.
Ok, the problem was that the users I had migrated to the aspnet database had null data in the Date Created field. Populating the field with a dummy date fixed everything.
Also a long time since this thread was refreshed, but I wanted to add what I think is a good answer so the next person that searches this will have something to go on:
Adding this code immediately helped me out - Suddenly Membership.GetUser() works!!! (I'm not sure if you need the Threading principal set, but I thought I'd leave that code for someone to determine their own needs or if using a Winforms or console app)
MembershipUser user = Membership.GetUser(username);
GenericIdentity identity = new GenericIdentity(user.UserName);
RolePrincipal principal = new RolePrincipal(identity);
System.Threading.Thread.CurrentPrincipal = principal;
HttpContext.Current.User = principal;
Alphonso
Member
32 Points
15 Posts
Re: Membership.GetUser() always returns null
Jan 18, 2006 07:36 PM|LINK
Still stuck.
I tried to use profiles, and save some profile manually (myProfile.save())..etc
I couldn't find a solution. Membership.GetUser() returns null all the time. No matter what!
Also, User.Identity.Name; is empty as well ( I mean even after successful authentication).
As mentioned earlier, on my very system I downloaded another app (mentioned above) and on this one app User.Identity.Name; returns the right user name and Membership.GetUser() doesn't return null but the expected User object ...
Please someone help I'm getting desesperate!!!
Alphonso
Member
32 Points
15 Posts
It's working now
Jan 18, 2006 07:52 PM|LINK
Hello,
It's working for me now! Here what I did. I added :
DisableCreatedUser="false"
I'm not sure that was solved my problem, I hope it helped someone.
Cheers, Alph.
PS: I added the above to the asp:CreateUserWizard control. (source view).
Alphonso
Member
32 Points
15 Posts
Re: It's working now
Jan 18, 2006 08:16 PM|LINK
Hello people :(
Well, I'm no longer sure it works... actually it does take some time for Membership.GetUser() to work correctly. I have to click here and there than comeback to the page where I check whether the successfuly logged-in User is "recognized" as such. So it is only after few clicks that Membership.GetUser() returns the right value (and no longer this bloody null value).
Hope someone can figure it out.
Pleaaaaasssssssseeee
sbrown73
Member
35 Points
7 Posts
Re: It's working now
Jan 19, 2006 02:11 PM|LINK
Specifically, in my web.config snippets above, where I set the local config for the "secure/" sub-section of my sebsite, this was incorrect. It was correct on my local machine, but on my public server the web app is actually sitting in a folder called "prototype" under the web root. So, that setting had to be changed to "prototype/secure/" and it started working.
Alphonso, my guess is that your problem will also turn out to be something related to your configuration.
-- Scott
starcoder
Member
10 Points
2 Posts
Re: Membership.GetUser() always returns null
Feb 09, 2006 11:39 AM|LINK
I have issued the same problem,
I think in LoggedIn event the httpcontext doesn't refresh itself because you cannot get the user identity calling by membership.getuser() or httpcontext.current.user.identity.name or system.security.threading.thread.currentprincipal.identity.name all these return null however when you are passed into destination page you can get the user information.
there is a problem with the logged in event while refreshing user httpcontext...
markberr
Participant
1148 Points
239 Posts
Microsoft
Re: Membership.GetUser() always returns null
Feb 14, 2006 03:12 PM|LINK
This is "by design". The initial request to the page is anonymous and an auth cookie is already set for this before the event is triggered. In the page response, an authenticated ticket cookie will be sent to the browser and subsequest page requests will include this cookie so that you'll have an authenticated user.
A workaround is to use the Login control to get the username. For example, "Login1.UserName".
Thanks,
Mark
Mark
This posting is provided "AS IS" with no warranties, and confers no rights.
rfogg
Member
20 Points
4 Posts
Re: Membership.GetUser() always returns null
Jun 14, 2006 10:43 PM|LINK
I have a similar problem. The resolutions here did not seem to work.
My code:
Sub
linkbutton1_click(ByVal sender As Object, ByVal e As EventArgs) Dim user As MembershipUser = Membership.GetUser()returns a Data is Null. This method or property cannot be called on Null values. error
The user has logged on successfully and makes it to the correct login view. Why does getuser return a null value?
Thanks in Advance
rfogg
Member
20 Points
4 Posts
Re: Membership.GetUser() always returns null
Jun 15, 2006 08:09 PM|LINK
gunalmel
Member
24 Points
22 Posts
Re: Membership.GetUser() always returns null
Feb 20, 2009 09:05 PM|LINK
I know it's been a long time since this thread was posted but I also had the sam problem for a very long time. Then I got my answer from:
http://forums.asp.net/t/1237126.aspx which referred to the simple solution at ScottGu's Blog:
http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx
I hope this will help others who would see this post just like me before spending much time.
Membership.GetUser Membership.GetAllUsers() returns null and 0
dstorfer
Member
54 Points
15 Posts
Re: Membership.GetUser() always returns null
Jun 08, 2010 06:09 PM|LINK
Also a long time since this thread was refreshed, but I wanted to add what I think is a good answer so the next person that searches this will have something to go on:
Adding this code immediately helped me out - Suddenly Membership.GetUser() works!!! (I'm not sure if you need the Threading principal set, but I thought I'd leave that code for someone to determine their own needs or if using a Winforms or console app)