Persist data in Profilecommon

Asked

Viewed 96 times

1

I created a website. 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 create my profile this way too:

//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 get a property from my profile that way. Profile.TipoPermissao but Profile comes empty, someone can help me?

1 answer

2

You have to recreate the profile object every time you upload information from your user. Therefore, here:

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

In the GetProfile you have to assemble the object again. How I answered you here, the method GetProfile need to assemble this object.

  • Gypsy there in the company once logged in, you do not need to load the data again you have access to profile attributes with Profile.Atributo. not needing to carry the profile again every time I access a different page.

  • @Marconi What do you mean? Profile does not necessarily depend on the session.

  • This variable profileCommon expires every time you change pages, so it cannot be trusted to persist with information. It is a read-only variable of your user information.

  • I find it strange because the company’s data remains in the profile, must have some Hbilitation within the web.conf.

  • 1

    I cracked the secret @Gypsy, the profile is integrated with mesmberships, which in turn creates ticket(cookie) to persist the information. I will improve this question on the weekend for me of better understanding and help more people.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.