Solved

problem with Assigning Profile and Role values during createduser event of createuserwizard

Posted on 2010-08-22
4
688 Views
Last Modified: 2012-05-10
Hello,

I have a create user wizard in an asp.net website.  I added the following code to the createduser event of the wizard:

but the line: "CreateUserWizard1.UserName.ToString" returns empty strings every time.  But in another website i have built this code works perfectly.  I can not figure out why this will not produce the username here.

thanks

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser



        Dim RegentDB As New RegentSignsDataContext

        Dim intError As Integer

        Dim intCompID As Integer

        Dim RGTProfile As ProfileCommon = ProfileCommon.Create(CreateUserWizard1.UserName.ToString, True)



        ''assign profile values

        Dim CustCompID = RegentDB.RGT_Customer_COMPID(hfCustID.Value, intCompID)

        RGTProfile.intCompanyID = intCompID

        RGTProfile.intCustomerID = hfCustID.Value

        RGTProfile.Email = CreateUserWizard1.Email

        RGTProfile.FullName = hfFirstName.Value + " " + hfLastName.Value

        RGTProfile.OldUserID = hfOldUserID.Value

        ''save profile

        RGTProfile.Save()



        ''assign role membership

        Dim chrUser As String

        chrUser = CreateUserWizard1.UserName.ToString

        If hfAdmin.Value = "YY" Then

            Roles.AddUserToRole("kingnolan", "RgtAdmin")

        ElseIf hfManager.Value = "y" Then

            Roles.AddUserToRole(chrUser, "ErManager")

        Else

            Roles.AddUserToRole(chrUser, "Erequest")

        End If



        ''update RgtTable user to be activated = 1

        Dim CustActivated = RegentDB.RGT_User_ACTIVATED(hfCustID.Value, intError)



    End Sub

Open in new window

0
Comment
Question by:jordanking
  • 3
4 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 33502900
An if you get the Usernae from RGTProfile?? Get an empty string too??
0
 
LVL 1

Author Comment

by:jordanking
ID: 33506097
RGTPRofile is not being created properly because there is no username being passed to its arguments "ProfileCommon.Create(username, isAuthenticated)", so it does not create a profile object and therefore has no username information.

The code i have work in another project I have, but something is not working in this specific situation.
0
 
LVL 1

Author Comment

by:jordanking
ID: 33510956
so I am narrowing down the issue, but still no solution.  The create user wizard has the following fields:  username, password, confirm password, email, security question, and answer.  The email and username fields are set programically in the page load event as follows:

Dim tbUserName = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox)
                tbUserName.Text = customer.chrUser

the "customer.chrUser" is from a recordset.field object that gets its information from sql server via LINQ.

As a result, the field values in the create user wizard that I set in the page load event are providing empty strings to the createdUser event.  The other fields that the user completes (ie password, security question, and answer) all work.

Therefore
CreateUserWizard1.UserName = "" an empty string
but
CreateUserWizard1.Question, CreateUserWizard1.Answer, CreateUserWizard1.Password all work and give the string value from the associated text boxes in the wizard


i can't figure out why this is hapening
0
 
LVL 1

Accepted Solution

by:
jordanking earned 0 total points
ID: 33512275
I figured out a solution:

get the username value the same way I set it programically in the page load event(by using findcontrol).  Also, I needed to add an update user call to the membership class after assigning the profile and roles to ensure the user is logged in after the wizard completes and redirects the page.

final working code follows:


Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser



        Dim RegentDB As New RegentSignsDataContext

        Dim intError As Integer

        Dim intCompID As Integer

        Dim tbUserName = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox)

        Dim strUser As String

        Dim tbEmail = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"), TextBox)

        Dim chrEmail As String



        strUser = tbUserName.Text

        chrEmail = tbEmail.Text



        Dim RGTProfile As ProfileCommon = ProfileCommon.Create(strUser, True)



        ''assign profile values

        Dim CustCompID = RegentDB.RGT_Customer_COMPID(hfCustID.Value, intCompID)

        RGTProfile.intCompanyID = intCompID

        RGTProfile.intCustomerID = hfCustID.Value

        RGTProfile.Email = chrEmail

        RGTProfile.FullName = hfFirstName.Value + " " + hfLastName.Value

        RGTProfile.OldUserID = hfOldUserID.Value

        ''save profile

        RGTProfile.Save()



        ''assign role membership

        If hfAdmin.Value = "YY" Then

            Roles.AddUserToRole(strUser, "RgtAdmin")

        ElseIf hfManager.Value = "y" Then

            Roles.AddUserToRole(strUser, "ErManager")

        Else

            Roles.AddUserToRole(strUser, "Erequest")

        End If



        Dim mUser As MembershipUser = Membership.GetUser(strUser)

        Membership.UpdateUser(mUser)

        FormsAuthentication.SetAuthCookie(strUser, False)

        ''update RgtTable user to be activated = 1

        Dim CustActivated = RegentDB.RGT_User_ACTIVATED(hfCustID.Value, intError)



    End Sub

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now