Assigning Profile Properties When A User Registers With CreateUserWizard

Discussion in 'ASP .Net Security' started by Nathan Sokalski, Jan 12, 2009.

  1. I am working with ASP.NET Membership, and want to assign values to the
    Profile properties when a user registers using the CreateUserWizard. I have
    the LoginCreatedUser property of my CreateUserWizard set to True, but when I
    use the HttpContext.Current.Profile.SetPropertyValue method in the
    CreatedUser event, it tells me I cannot set this for anonymous users. Where
    and how should I set any Profile properties I want to set during
    registration? Thanks.
    Nathan Sokalski, Jan 12, 2009
    1. Advertisements

  2. Nathan Sokalski

    miher Guest

    I think You have to wait with setting Profile values until the user gets
    created, and she gets logged in.
    A suitable event can be the ContinueButtonClick event of the wizard, what is
    fired if the Continue button is clicked on the second(finish) page of a
    default wizard.
    In the handler of this event You should be able to set Profile values.

    Hope You find this useful.
    miher, Jan 12, 2009
    1. Advertisements

  3. Nathan Sokalski

    Paul Shapiro Guest

    I tried setting profile properties in the CreateUserWizard.CreatedUser
    event, but I got the same error about an anonymous user. I thought from the
    documentation that both the user and the profile would already exist:
    "Use the CreatedUser event to set Web site values, such as
    personalization values, before the user is logged on to the site for the
    first time."

    Maybe the user exists, but it doesn't seem the Profile exists yet. I moved
    the code to a page event, where it now checks to see if the Profile has been
    initialized. I would also like to find a more appropriate event for initial
    Profile setup.
    Paul Shapiro, Jan 13, 2009
  4. I finally found an answer, take a look at:

    I'm not sure where the class ProfileCommon comes from, because I have been
    unable to get Intellisense to list it, but when I use ProfileBase instead
    everything works fine. Here is a copy of my code just so you can see what I

    Private Sub cuwRegister_CreatedUser(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles cuwRegister.CreatedUser
    Dim tempprofile As ProfileBase =
    ProfileBase.Create(Me.cuwRegister.UserName, True)
    Dim bday As String =
    Dim loc As String =
    Dim site As String =

    If Not String.IsNullOrEmpty(bday) Then
    tempprofile.SetPropertyValue("Birthday", CDate(bday))
    If Not String.IsNullOrEmpty(loc) Then
    tempprofile.SetPropertyValue("LanguageOfChoice", loc)
    If Not String.IsNullOrEmpty(site) Then
    tempprofile.SetPropertyValue("PersonalWebsite", site)
    End Sub

    Hopefully this will save you some of the frustration that I had, good luck!
    Nathan Sokalski, Jan 13, 2009
  5. Nathan Sokalski

    Paul Shapiro Guest

    Thanks very much! That's a big help.

    Paul Shapiro, Jan 15, 2009
  6. Nathan Sokalski

    FlashMerlot Guest

    Been looking for this solution ...
    FlashMerlot, Mar 11, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.