Solved

Why can't I use the Membership.GetUser.ProviderUserKey in the Login.LoggedIn event?

Posted on 2008-10-02
5
856 Views
Last Modified: 2012-05-05
Hello,

Can you tell me what is wrong with the code I attach? When I run it I get this: "Object reference not set to an instance of an object."

If I understand correctly, the membership object has not yet been created. But when is it created? I need to execute a piece of code every time an user logs in (at the beginning of each session). And I need the UserId for that code.

Is there another event I can use to execute my code after the user logs in but before the user sees any page in the application?

Thanks in advance.
Protected Sub Login_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login.LoggedIn
 

    Dim UserId As Guid = Membership.GetUser.ProviderUserKey
 

End Sub

Open in new window

0
Comment
Question by:richardhaeger
  • 4
5 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 22631095
Hi, try this


Dim guidString As String = Membership.GetUser.ProviderUserKey()

Dim UserId As Guid = New Guid(guidString)

Open in new window

0
 

Author Comment

by:richardhaeger
ID: 22637262
Hello RedKelvin,

Your suggestion didn't work. I keep getting the "Object reference not set to an instance of an object." message in line 1 of your code.

Only thing I can think of is that the membership object is not yet created when the logged in event occurs.

Thanks anyway.

Any more ideas?
0
 

Author Comment

by:richardhaeger
ID: 22637860
I found the reason why the code fails (I still need a solution).

This works:

Protected Sub Login_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login.LoggedIn

    Dim UserId As Guid = Membership.GetUser(Login.UserName).ProviderUserKey

Then I can process my code to retrieve the company Id of the user that is being logged in, but if I try this:

Profile.CompanyId = CompanyId

An errors occurs saying I cannot set the profile properties of the anonymous user.

So at this point the user is still recognized as anonymous!

What event fires right after logged in? I need to run my code as soon as the user is REALLY logged in, before he sees any other page.

Please help! Thanks in advance.
0
 

Author Comment

by:richardhaeger
ID: 22637944
0
 

Accepted Solution

by:
richardhaeger earned 0 total points
ID: 22638151
I found this solution at http://forums.asp.net/t/1096144.aspx:

Profile.Initialize(Login1.UserName, true);

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now