Solved

Wizard used to register users need help with profile creation

Posted on 2009-07-15
18
904 Views
Last Modified: 2012-05-07
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
Comment
Question by:woodje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24864028
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
 

Author Comment

by:woodje
ID: 24864357
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
 

Author Comment

by:woodje
ID: 24864364
the url guid is ?ID=3195c483-f32d-42e0-a9df-df499843bc7f
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 41

Expert Comment

by:guru_sami
ID: 24864472
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 24864491
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
 

Author Comment

by:woodje
ID: 24864620
The code worked however it did not save the data to the aspnet_Profile table.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24866073
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
 

Author Comment

by:woodje
ID: 24871628
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 24871681
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
 

Author Comment

by:woodje
ID: 24871684
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 24871712
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
 

Author Comment

by:woodje
ID: 24871728
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 24871746
alrite I was about to tell you about that as well:
Set:
  <profile enabled="true" defaultProvider="fss_caoProfileProvider" >
0
 

Author Comment

by:woodje
ID: 24871773
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
 
LVL 41

Expert Comment

by:guru_sami
ID: 24871832
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
 

Author Comment

by:woodje
ID: 24872139
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
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 24872180
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
 

Author Comment

by:woodje
ID: 24872237
Just found that article. And Added it worked and stored the data. Thanks so much for all your help.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

632 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