Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 417395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:34:33+00:00 2026-05-12T18:34:33+00:00

In ASP.Net, I am trying to get the UserId (i.e., the user GUID) of

  • 0

In ASP.Net, I am trying to get the UserId (i.e., the user GUID) of the user that just logged on, in the LoggedIn event of the Login control. That is, I want to grab the UserId before the user is moved to to the next page. This is the code I am using:

Protected Sub Login1_LoggedIn(ByVal sender As Object, _
  ByVal e As System.EventArgs) Handles Login1.LoggedIn

    Dim UserId As String
    UserId = Membership.GetUser.ProviderUserKey.ToString()

End Sub

However, I get an “Object reference not set to an instance of an object” error. This same code works well when I use it in subsequent pages, when a logged in user is accessing these pages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:34:34+00:00Added an answer on May 12, 2026 at 6:34 pm

    ScottGu has the answer to this problem, as explained in this blog post on the ASP.NET Forum:

    The LoggedIn event fires immediately
    after the user is logged in with the
    login control — but not before the
    next request to the site. As such,
    the User object isn’t filled out yet.

    If you change your code to something like:

    Dim UserId As String
    UserID = Membership.GetUser(Login1.UserName).ProviderUserKey.ToString()
    

    It should work fine. Calling Membership.GetUser without passing the Username as a parameter will expect to grab the “current” logged in user. Of course, this fails for the above reasons as the User object is not yet populated. By passing the Login control’s UserName property as a parameter to the GetUser() method, you explicitly force the Membership.GetUser method to retrieve the user as specified by name from the user store (i.e. database). This ensures that the Membership.GetUser method returns a valid MembershipUser object which allows you to access the ProviderUserKey property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with ASP.NET MVC3, and I'm trying to get absolute control over my
I am trying to get the currently logged in user's UserId as mentioned in
I am trying to get an ASP.NET 3.5 ListView control to select and highlight
I'm trying to get the OnKeyPress event to work for a ASP.NET ListBox which
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
I am trying to get a ASP.NET Unit Test running and I keep getting
I am trying to get ASP.Net MVC 4 working on IIS6 and am running
I'm trying to get the new ASP.NET Web API beta (VS 2010 default Web
I'm trying to get my mysql data in ASP.net MVC3. The mysql Database Name
I am trying to get a handle on Solrnet and interacting an ASP.NET site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.