Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-02
5
Medium Priority
?
867 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

604 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