Persisting data in ProfileCommon

1

I created a web site. Asp.net C #

I added in my web config this way

<authentication mode="Forms" >
  <forms loginUrl="principal.aspx"
  name=".ASPXFORMSAUTH" />
</authentication>

<roleManager defaultProvider="SqlProvider"
  enabled="true"
  cacheRolesInCookie="true"
  cookieName=".ASPROLES"
  cookieTimeout="30"
  cookiePath="/"
  cookieRequireSSL="false"
  cookieSlidingExpiration="true"
  cookieProtection="All" >
  <providers>
    <add
      name="SqlProvider"
      type="System.Web.Security.SqlRoleProvider"
      connectionStringName="labPuc"
      applicationName="/" />
  </providers>
</roleManager>
<compilation debug="true" targetFramework="4.5">
  <assemblies>
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  </assemblies>
</compilation>
<httpRuntime targetFramework="4.5"/>
<membership defaultProvider="SqlMembershipProvider">
  <providers>
    <clear/>
    <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="labPuc" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" minRequiredNonalphanumericCharacters="2" minRequiredPasswordLength="6" maxInvalidPasswordAttempts="3"/>
  </providers>
</membership>
<profile defaultProvider="AspNetSqlProfileProvider">
  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" applicationName="/" connectionStringName="labPuc"/>
  </providers>
  <properties>
    <add name="UserId" type="System.String"/>
    <add name="Email" type="System.String"/>
    <add name="TipoPermissao" type="System.String"/>
    <add name="Habilitado" type="System.String"/>
  </properties>
</profile>

When I create a user I also create my profile this way:

//Provedor de perfil
ProfileCommon perfil = (ProfileCommon)ProfileCommon.Create(login.Text, true);
perfil.UserId = user.ProviderUserKey.ToString();
perfil.Email = user.Email;
perfil.Habilitado = "S";
perfil.TipoPermissao = "Administrador";
perfil.Save();

So far so good. When I log in I get ProfileCommon like this:

ProfileCommon profile = Profile.GetProfile(Login.Text);

When I'm redirected to another page, I try to pick up a property from my profile in this way. Profile.TipoPermissao But the Profile is empty, can anyone help me?

    
asked by anonymous 27.09.2014 / 03:12

1 answer

2

You have to re-create the profile object each time you upload your user information. So here:

ProfileCommon profile = Profile.GetProfile(Login.Text);

No GetProfile you have to mount the object again. As I replied here , the GetProfile method needs to mount this object.

    
28.09.2014 / 03:25