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

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jan 12, 2009
    #1
    1. Advertising

  2. Nathan Sokalski

    miher Guest

    Hi,
    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.
    -Zsolt

    "Nathan Sokalski" <> az alábbiakat írta a következõ
    üzenetben news:...
    > 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
    >
    > http://www.nathansokalski.com/
    >
     
    miher, Jan 12, 2009
    #2
    1. Advertising

  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.

    "miher" <> wrote in message
    news:...
    > Hi,
    > 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.
    > -Zsolt
    >
    > "Nathan Sokalski" <> az alábbiakat írta a következõ
    > üzenetben news:...
    >> 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
    >>
    >> http://www.nathansokalski.com/
     
    Paul Shapiro, Jan 13, 2009
    #3
  4. I finally found an answer, take a look at:

    http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

    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
    did:

    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 =
    CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtBirthday"),
    TextBox).Text
    Dim loc As String =
    CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("ddlLangOfChoice"),
    DropDownList).SelectedValue
    Dim site As String =
    CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtWebsite"),
    TextBox).Text

    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)
    tempprofile.Save()
    End Sub

    Hopefully this will save you some of the frustration that I had, good luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Paul Shapiro" <> wrote in message
    news:...
    >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.
    >
    > "miher" <> wrote in message
    > news:...
    >> Hi,
    >> 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.
    >> -Zsolt
    >>
    >> "Nathan Sokalski" <> az alábbiakat írta a következõ
    >> üzenetben news:...
    >>> 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
    >>>
    >>> http://www.nathansokalski.com/

    >
     
    Nathan Sokalski, Jan 13, 2009
    #4
  5. Nathan Sokalski

    Paul Shapiro Guest

    Thanks very much! That's a big help.

    "Nathan Sokalski" <> wrote in message
    news:...
    >I finally found an answer, take a look at:
    >
    > http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx
    >
    > 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 did:
    >
    > 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 =
    > CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtBirthday"),
    > TextBox).Text
    > Dim loc As String =
    > CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("ddlLangOfChoice"),
    > DropDownList).SelectedValue
    > Dim site As String =
    > CType(Me.cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtWebsite"),
    > TextBox).Text
    >
    > 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)
    > tempprofile.Save()
    > End Sub
    >
    > Hopefully this will save you some of the frustration that I had, good
    > luck!
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Paul Shapiro" <> wrote in message
    > news:...
    >>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.
    >>
    >> "miher" <> wrote in message
    >> news:...
    >>> Hi,
    >>> 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.
    >>> -Zsolt
    >>>
    >>> "Nathan Sokalski" <> az alábbiakat írta a
    >>> következõ üzenetben news:...
    >>>> 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
    >>>>
    >>>> http://www.nathansokalski.com/

    >>

    >
    >
     
    Paul Shapiro, Jan 15, 2009
    #5
  6. Nathan Sokalski

    FlashMerlot Guest

    Re: Assigning Profile Properties When A User Registers With Create

    Outstanding!
    Been looking for this solution ...
    --
    F.V.
     
    FlashMerlot, Mar 11, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad
    Replies:
    1
    Views:
    1,141
    Roedy Green
    Jul 19, 2005
  2. Pedro Mir
    Replies:
    1
    Views:
    469
  3. Steven
    Replies:
    5
    Views:
    494
    Steven
    Oct 24, 2008
  4. Nathan Sokalski
    Replies:
    5
    Views:
    705
    FlashMerlot
    Mar 11, 2009
  5. weston
    Replies:
    1
    Views:
    253
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page