views:

191

answers:

2

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!

+2  A: 

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>
thinkzig
Yup, same connectionstring. The very odd thing is that this works on Staging/Production but not locally. So I'm always afraid to push anything to Production since this doesn't work locally. I'm wondering if its a timeout issue?
Jack Marchetti
Okay. Question 2. Do you have a different web.config for each environment? Or do you just edit the connection strings for the same web.config file when you move between environments?
thinkzig
I have different connection strings for production/staging/dev but not different web.configs.
Jack Marchetti
+1  A: 

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>
Jon Freeland
Where would that be set, I don't see that set anywhere in my web.config
Jack Marchetti
Updated my answer.
Jon Freeland