Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

Wizard used to register users need help with profile creation

I have a Wizard that I use to register users when they recieve an email from the admin. I am able to have the user update the membership data. But I can't get the profile entry to be created. I have the following data in my web.config file.

 <profile enabled="true">
      <properties>
        <add name="fname" type="string"/>
        <add name="lname" type="string"/>
      </properties>

And then I have the below code in my Wizard1_NextButtonClick event

I think it is something in my syntax on the profile infomation below the memebership update
Protected Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick
        Dim tbPassword As TextBox = DirectCast(Wizard1.FindControl("Password"), TextBox)
        Dim ddlQuestion As DropDownList = DirectCast(Wizard1.FindControl("sec_ques_1_list"), DropDownList)
        Dim tbAnswer As TextBox = DirectCast(Wizard1.FindControl("Answer"), TextBox)
 
        Dim newPassword As String = tbPassword.Text
        Dim pwdQuestion As String = ddlQuestion.SelectedValue.ToString()
        Dim pwdAnswer As String = tbAnswer.Text
 
        Dim userId As Guid = New Guid(Request.QueryString("ID"))
        Dim userInfo As MembershipUser = Membership.GetUser(userId)
 
        userInfo.ChangePassword(userInfo.ResetPassword(), newPassword)
 
        userInfo.ChangePasswordQuestionAndAnswer(newPassword, pwdQuestion, pwdAnswer)
 
        userInfo.IsApproved = True
 
        Membership.UpdateUser(userInfo)
 
        ' Create an empty Profile for the newly created user 
        Dim p As ProfileCommon = DirectCast(ProfileCommon.Create=Int32.Parse(DirectCast(userId,string), ProfileCommon)
 
        ' Populate some Profile properties off of the create user wizard 
        p.fname = Int32.Parse(DirectCast(WizardStep1.FindControl("profile_fname_txt"), TextBox).Text)
        p.lname = Int32.Parse(DirectCast(Wizard1.FindControl("profile_lname_txt"), TextBox).Text)
 
        Profile.fname = profile_fname_txt.Text
        Profile.lname = profile_lname_txt.Text
 
        ' Save profile - must be done since we explicitly created it 
        p.Save()
    End Sub

Open in new window

0
woodje
Asked:
woodje
  • 9
  • 9
1 Solution
 
guru_samiCommented:
just wondering...is your username = userId
ProfileCommon.Create takes username as a paramter...

Do you mind trying this:
Dim p As ProfileCommon = DirectCast(ProfileCommon.Create(yourusername), ProfileCommon)
0
 
woodjeAuthor Commented:
Yes the userId is the username and I grab this from the QueryString=ID

I entered my ID hard coded and the page loads however when it gets to the next line it errors out saying "System.FormatException: Input string was not in a correct format." this is on the line

p.fname = Int32.Parse(DirectCast(Wizard1.FindControl("profile_fname_txt"), TextBox).Text)
0
 
woodjeAuthor Commented:
the url guid is ?ID=3195c483-f32d-42e0-a9df-df499843bc7f
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
guru_samiCommented:
why you have Int32.Parse ? your fname is a string value right...
try like this:
p.fname = DirectCast(Wizard1.FindControl("profile_fname_txt"), TextBox).Text;
0
 
guru_samiCommented:
and I think you should this:
 Dim p As ProfileCommon = DirectCast(ProfileCommon.Create=Int32.Parse(DirectCast(userId,string), ProfileCommon)
 and try like this:

Dim p As ProfileCommon = DirectCast(ProfileCommon.Create(userId .ToString), ProfileCommon)
0
 
woodjeAuthor Commented:
The code worked however it did not save the data to the aspnet_Profile table.
0
 
guru_samiCommented:
hey just wondering are you having seperate connectionString for your membership/roles provider?
If yes then you need to set your profile provider as well to point to the correct database using the same connectionString.
Here is an example:
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" connectionStringName="YourConnectionStringName" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<properties>
        <add name="fname" type="string"/>
        <add name="lname" type="string"/>
 </properties>
</providers>
</profile>

If your membership aspnetDB is not in App_Data folder...
Refresh your Solution and  check under app_data folder if a new aspnetDB is added..
IF yes then check in there if the profile you saved is added in the profiles table.
0
 
woodjeAuthor Commented:
Here is the data from my web.config file
<membership defaultProvider="fss_caoMembershipProvider">
      <providers>
        <add connectionStringName="fss_cao_SqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="FinanceUnifiedDatabase" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="3" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="fss_caoMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
    </membership>
    <profile enabled="true">
      <properties>
        <add name="fname" type="string"/>
        <add name="lname" type="string"/>
      </properties>      
      <providers>
        <add name="fss_caoProfileProvider" connectionStringName="fss_cao_SqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
    </profile>
    <roleManager enabled="true" defaultProvider="fss_caoRoleProvider">
      <providers>
        <add connectionStringName="fss_cao_SqlServer" applicationName="FinanceUnifiedDatabase" name="fss_caoRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
    </roleManager>

Open in new window

0
 
guru_samiCommented:
did you see there is not seperate aspnetdb under your app_Data folder and if your profiles are getting stored there?

try adding <clear /> in your profile provider, then try and see if it saving.

<providers>
<clear />
        <add name="fss_caoProfileProvider" connectionStringName="fss_cao_SqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>

Also it would be good to set applicationName="FinanceUnifiedDatabase" ...same as your membership and role providers..
0
 
woodjeAuthor Commented:
You are right it did add the value to the aspnetdb.mdf file in the app_data folder instead of the sql database? Why is that?
0
 
guru_samiCommented:
because it is using the default profileProvider settings from your machine.config...check there.
<clear /> will clear up any settings inherited from your machie.config.
0
 
woodjeAuthor Commented:
I added the clear and it is getting an error.

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The profile default provider was not found.

Source Error:


Line 78:       </providers>
Line 79:     </membership>
Line 80:     <profile enabled="true">
Line 81:       <properties>
Line 82:         <add name="fname" type="string"/>
 

Source File: C:\Inetpub\wwwroot\pfo_gateway\web.config    Line: 80
0
 
guru_samiCommented:
alrite I was about to tell you about that as well:
Set:
  <profile enabled="true" defaultProvider="fss_caoProfileProvider" >
0
 
woodjeAuthor Commented:
Well we keep making progress added teh default provider. And now I am getting a new error.

This property cannot be set for anonymous users.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Configuration.Provider.ProviderException: This property cannot be set for anonymous users.

Source Error:


Line 22:         }
Line 23:         set {
Line 24:             this.SetPropertyValue("fname", value);
Line 25:         }
Line 26:     }
 

Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\pfo_gateway\dcfc321d\d051b320\App_Code.kxam-8oz.0.cs    Line: 24
0
 
guru_samiCommented:
Wonderful ..getting more and more complex...
That is because at this point your user is not logged-in.
set:
 <add name="fname" type="string" allowAnonymous="true"/>
        <add name="lname" type="string" allowAnonymous="true"/>

Then you need to migrate this once user is logged-in... do some modifications in your Global.asax.
Check this here:
http://www.eggheadcafe.com/articles/20060529.asp
0
 
woodjeAuthor Commented:
I have adjusted my code as you have outlined. And have created an global.asax file and coded it according to the article you provided. However I am still getting an error. But as usual it is different.

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The Profile property 'fname' allows anonymous users to store data. This requires that the AnonymousIdentification feature be enabled.

Source Error:


Line 80:     <profile enabled="true" defaultProvider="fss_caoProfileProvider">
Line 81:       <properties>
Line 82:         <add name="fname" type="string" allowAnonymous="true"/>
Line 83:         <add name="lname" type="string" allowAnonymous="true"/>
Line 84:       </properties>      
 

Source File: C:\Inetpub\wwwroot\pfo_gateway\web.config    Line: 82

However when I try set the  AnonymousIdentification feature to enabled it is not found in the function on the line that it outlines.
0
 
guru_samiCommented:
cool...you should add this to your web.config:
<anonymousIdentification enabled="true" />
<profile enabled="true" defaultProvider="fss_caoProfileProvider" >
....
...
FYI: http://msdn.microsoft.com/en-us/library/ewfkf772.aspx
0
 
woodjeAuthor Commented:
Just found that article. And Added it worked and stored the data. Thanks so much for all your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now