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

  • SEARCH
  • Home
  • 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 9151447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:48:16+00:00 2026-06-17T11:48:16+00:00

How do I get User ID for new registered user in ASP.Net CreateUserWizard? I

  • 0

How do I get User ID for new registered user in ASP.Net CreateUserWizard?

I have a page that allows new users to register with a Create User Wizard. Right after a user is created I would like to insert a row in a customer details table using the new user’s User ID and email.

I tried putting some code in the CreateUserWizard1_CreatedUser to get the User ID. But, from what I learned, the user is created at this point; but, the user is not logged in at this point. I get an error that says…

“NullReferenceException” was handled by user code.
Object not set to an instance of an object.”

If I put a breakpoint in during debugging I can see that the value of the customerId is null.

From what I read on the MSDN site, the CreatedUser event…
“Occurs after the membership provider has created the new Web site user account.”

I want to add the row to the customer details table before the Create User Wizard changes to display the “Continue” button. At that point, the user can go to other pages or close the application.

Is there some other event after the CreatedUser where I can put some code?
I see that there is an Unload event.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.createuserwizard_events%28v=vs.110%29.aspx

Can I can somehow log in the user in the CreatedUser event to get the User ID?


Here is my code on the Register page that isn’t working. The error occurs on the line of code: “string customerId =”

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
    // Add the Role of Customers to the new user.
    Roles.AddUserToRole((sender as CreateUserWizard).UserName, "Customers");

    // Get the current user's ID and email
    string customerId = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString();
    string email = Membership.GetUser(HttpContext.Current.User.Identity.Name).Email.ToString();
    bool success = CustomerDetailsAccess.CreateCustomerDetails(customerId, email);

…

}
  • 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-06-17T11:48:17+00:00Added an answer on June 17, 2026 at 11:48 am

    When a user is going through the registration process, HttpContext.Current.User.Identity would not be set (anonymous access) unless the user registering is already logged in.

    To solve the problem, you will need to get the username from the wizard instead of the context.

    To fix the issue, change the following line:

    string customerId = Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString();
    

    to this:

    string customerId = Membership.GetUser((sender as CreateUserWizard).UserName).ProviderUserKey.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My ASP.NET MVC site allows users to register and give themselves user names, which
I have an ASP.NET page with two instances of the same Web User Control
I'm maintaining an ASP.NET site where users can log on to register some set
I would like to create user in my user table when new user have
I have looked through examples on using JQuery in asp.net user controls and when
I am fairly new to azure, wcf, asp.net and json. I have experience with
I'm inserting a row in the users table to register a new user. I
I need to create a web page (using asp.net MVC2 and possibly WCF) showing
I'm new to ASP.NET MVC so this may be a stupid question. I have
im new to google maps, i used html5 to get user's cordinates of latitude

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.