简体   繁体   中英

ASP.NET Membership not populating new users

I'm using the ASP.NET Membership provider to handle all membership activities on my current site.

I've run into a weird problem. As you know, if you are familiar with Asp.Net membership, the data is stored in ProfileCommon.

So you could do ProfileCommon.UserId to get the userID.

This all works fine on my production server, my staging server and for old accounts on my local dev server.

However, if I create a new user on my local dev server, the Profilecommon object is not being populated and it is throwing errors because pages reference ProfileCommon.UserId for instance and it's null, thus throwing an exception. The user is Authenticated, but ProfileCommon is not being populated.

Does anyone have any ideas/suggestions as to why this might be happening?

Edit: here's my web.config entry. I'm not sure why we remove AspnetSqlProfileProvider then add it. This is a site I took over and I'm not 100% familiar with asp.net membership yet.

  <profile defaultProvider="AspNetSqlProfileProvider">
  <providers>
    <remove name="AspNetSqlProfileProvider"/>
    <add name="AspNetSqlProfileProvider"
         type="System.Web.Profile.SqlProfileProvider" 
         connectionStringName="ConnectionString"/>
</providers>

Actual profile info;

        <profile defaultProvider="SqlProfileProvider">
        <providers>
            <remove name="AspNetSqlProfileProvider"/>
            <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="FiftyMillionDBConnection"/>
        </providers>
        <properties>
            <add name="FirstName" type="String" serializeAs="String"/>
            <add name="LastName" type="String" serializeAs="String"/>
            <add name="EmailAddress" type="String" serializeAs="String"/>
            <add name="ScreenName" type="String" serializeAs="String"/>
            <add name="BirthDay" type="DateTime" serializeAs="String"/>
            <group name="Address">
                <add name="AddressLine1" type="String" serializeAs="String"/>
                <add name="AddressLine2" type="String" serializeAs="String"/>
                <add name="City" type="String" serializeAs="String"/>
                <add name="State" type="String" serializeAs="String"/>
                <add name="Zip" type="String" serializeAs="String"/>
            </group>
            <group name="PersonalInfo">
                <add name="Gender" type="String" serializeAs="String"/>
                <add name="Height" type="String" serializeAs="String"/>
            </group>
            <group name="OtherInfo">
                <add name="Agent" type="String" serializeAs="String"/>
                <add name="Employee" type="String" serializeAs="String"/>
                <add name="Source" type="String" serializeAs="String"/>
                <add name="EventRegistration" type="String" serializeAs="String"/>
            </group>
            <group name="AuthInfo">
                <add name="GUID" type="String" serializeAs="String"/>
                <add name="RegSource" type="String" serializeAs="String"/>
                <add name="ReceiveMail" type="String" serializeAs="String"/>
            </group>
        </properties>
    </profile>

Thank you!

Is the Profile section in web.config using the same connectionStringName value as the Membership section? This is the first thing I would check.

Edit: Can you post your full profile config block? You should have something that defines the properties like

<profile enabled="true">

    <properties>

        <add name="UserId" type="Int32"/>

        <add name="Gender" type="string"/>

        <add name="Age" type="Int32"/>

    </properties>

</profile>

In addition to the connectionStringName , you may also want to double-check applicationName . If they don't match, or you define the application name in one section and not the other, you'll run into issues.

   <membership defaultProvider="SqlProvider">
      <providers>
         <add name="SqlProvider"
          type="..."  
          connectionStringName="SomeConnString"
          applicationName="SomeApp"
          ...
          ... />
      </providers>
   </membership>

   <profile defaultProvider="ProfileProvider">
     <providers>
        <clear />
        <add name="ProfileProvider" 
            type="..." 
            applicationName="SomeApp"/>
     </providers>
     <properties>
        ...
     </properties>
  </profile>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM