Asp.net Profile Not Saving or displaying entered data (Code Updated) 10/28/12

1.4k views Asked by At

Asp.net profile is either not displaying or saving the data the user enters, However there is No Errors. here is a view of the code below: the webproject just Runs and nothing is displayed on both firstname amd lastname label.


This is A WEB PROJECT ,,, I opened the project using OPEN WEBSITE!
HOWEVER the Project Displays it as "WEBPROJECT.sln(3)" at the program title bar of VISUAL STUDIOS.

This is when the user creates the account and saves the users profile settings: NEW AND UPDATED

protected void CreateUserWizard_CreatedUser(object sender, EventArgs e)
{
    // Create an empty Profile for the newly created user
    ProfileCommon p = (ProfileCommon)ProfileCommon.Create(RegisterUser.UserName, true);

    // Save profile - must be done since we explicitly created it

    TextBox txtNewFirstName = (TextBox)RegisterUser.FindControl("txtNewFirstName");
    Profile.FirstName = txtNewFirstName.Text;


    TextBox txtNewLastName = (TextBox)RegisterUser.FindControl("txtNewLastName");
    Profile.LastName = txtNewLastName.Text;


    p.Save();
}

And this is when its is displayed: NEW AND UPDATED

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
            ProfileCommon p = this.Profile.GetProfile(this.User.Identity.Name);

            Label firstName = (Label)LoginView1.FindControl("firstName");
           Profile.FirstName = firstName.Text;


            Label lastName = (Label)LoginView1.FindControl("lastName");
           Profile.LastName = lastName.Text;


    } 
}

And this is the Web config: NEW AND UPDATED

 <profile defaultProvider="AspNetSqlProfileProvider" enabled="true">
  <properties>
    <add name="FirstName" type="String" serializeAs="String"/>
    <add name="LastName" type="String" serializeAs="String"/>
    <add name="Gender" type="String" serializeAs="String"/>
    <add name="BirthDate" type="DateTime" serializeAs="String"/>
    <add name="Occupation" type="String" serializeAs="String"/>
    <add name="Website" type="String" serializeAs="String"/>
    <group name="Forum">
      <add name="Posts" type="Int32" defaultValue="0"/>
      <add name="AvatarUrl" type="String" serializeAs="String"/>
      <add name="Signature" type="String" serializeAs="String"/>
    </group>
    <group name="Address">
      <add name="Street" type="String" serializeAs="String"/>
      <add name="PostalCode" type="String" serializeAs="String"/>
      <add name="City" type="String" serializeAs="String"/>
      <add name="State" type="String" serializeAs="String"/>
      <add name="Country" type="String" serializeAs="String"/>
    </group>
    <group name="Contacts">
      <add name="Phone" type="String" serializeAs="String"/>
      <add name="Fax" type="String" serializeAs="String"/>
    </group>
  </properties>

  <providers>
 <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
  </providers>
</profile>

This is Whats being displayed on the aspnet_Profile on my sql server:
[PropertyNames]
[LastName:S:0:0:FirstName:S:0:0:]

This is redone of the previous code so please ignore previous comments below!

I have also Tryed PreRender Method:

<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
            ProfileCommon p = this.Profile.GetProfile(this.User.Identity.Name);

            Label firstName = (Label)LoginView1.FindControl("firstName");
           Profile.FirstName = firstName.Text;


            Label lastName = (Label)LoginView1.FindControl("lastName");
           Profile.LastName = lastName.Text;

}

But i get a error: Object reference not set to an instance of an object. for Profile.FirstName = firstName.Text;

1

There are 1 answers

7
IrishChieftain On BEST ANSWER

Simplify it by removing all properties from Web.Config except for the first and last name properties. Try to narrow it down.

The following works for me. Although I set anonymousIdentification to true for convenience, I've given you the full syntax for a working membership Web.Config entry:

<configuration>
  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" 
        connectionString="Initial Catalog=Test;Data Source=MYPCNAME;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <anonymousIdentification enabled="true"/>
    <profile>
      <properties>
        <add name="FirstName" type="System.String" allowAnonymous="true"/>
        <add name="LastName" type="System.String" allowAnonymous="true"/>
      </properties>
    </profile>
    <roleManager enabled="true"/>
    <authentication mode="Forms">
      <forms timeout="50000000"/>
    </authentication>
    <membership defaultProvider="SqlProvider">
      <providers>
        <clear/>
        <add name="SqlProvider" 
            type="System.Web.Security.SqlMembershipProvider"
            connectionStringName="LocalSqlServer" 
            enablePasswordReset="true" 
            requiresQuestionAndAnswer="false" 
            requiresUniqueEmail="false" 
            maxInvalidPasswordAttempts="5" 
            passwordAttemptWindow="10" 
            passwordFormat="Hashed" 
            minRequiredPasswordLength="7" 
            minRequiredNonAlphanumericCharacters="0" 
            passwordStrengthReqularExpression="0" 
            enablePasswordRetrieval="false" 
            applicationName="/"/>
      </providers>
    </membership>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
</configuration>

    protected void Button1_Click(object sender, EventArgs e)
    {
        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(fnTxt.Text 
            + lnTxt.Text, true);
        Profile.FirstName = fnTxt.Text;
        Profile.LastName = lnTxt.Text;

        p.Save();
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        resultLabel.Text = Profile.FirstName + " " + Profile.LastName;
    }