Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using asp.net membership. My login.aspx page goes to the loginredirect.aspx
page after the user logs in.

For some reason "Membership.GetUser.ProviderUserKey.ToString" gives me this
error:
System.NullReferenceException: Object reference not set to an instance of an
object.

Any reason why? I should be logged in fine.

Is there another way in which I should get the current users UserId?

thanx in advance..
Posted
Comments
Al Moje 10-Feb-12 0:09am    
Use ASP.Net Web Site Administration Tool
On your project Solution click the icon 'ASP.NET Configuration'
Use ASP.Net Web Site Administration Tool then setup/configure the following:
Security
Application
Provider

You need to do Membership.GetUser and see if it's null. If it's null than you're not logged in. Your example code string provides two instances I can see where a null ref can occur. 1) if getuser returns null and 2) if ProviderUserKey is null.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Feb-12 1:27am    
Sure, a 5. And thanks to you note, I fixed my mistake in my answer. :-)
--SA
Tech Code Freak 11-Feb-12 6:28am    
5up!
Always use the Debugger. Elementary, Watson.

One possible reason is:
Membership.GetUser == null.

If not, another possible reason is:
Membership.GetUser.ProviderUserKey == null.

And that's it, nothing except these two cases. But if you used the Debugger, you would not need to write a single line on this CodeProject page.

Best regards,
—SA
 
Share this answer
 
v3
Comments
Nathan Stiles 10-Feb-12 0:31am    
What? Membership can't be null, it's a static class.
Sergey Alexandrovich Kryukov 11-Feb-12 1:25am    
Oh, my bad! I tried to write it in a blindfolded way and did this mistake. Will fix. Thank you very much for your help.
--SA
Espen Harlinn 11-Feb-12 5:08am    
5'ed!
Sergey Alexandrovich Kryukov 11-Feb-12 5:20am    
Thank you, Espen.
--SA
Tech Code Freak 11-Feb-12 6:28am    
5up!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900