Search code examples
c#asp.net-membershipmembership-provider

How to handle CustomizedProvider in C#


I am facing one freak problem in one asp.net project. Actually this is not my own code i am doing research on someone else code. This project is bind with Membership provider. The problem is that each and every time when i run this project it inserts new row in aspnet_Profile and aspnet_Users membership tables and if i run this same page again then it update these two tables column LastUpdatedDate in aspnet_Profile table and LastActivityDate in aspnet_Users table with current date and time.

Because of that i have more then 1lac of entries in these two tables.I want to know that why it happens. I tested the code but not found any solution but still i am thinking that it causes because of web.cofig file because in that file we have mentioned membership provider.

Here is how my Membership Provider is configured:

<membership defaultProvider="CustomizedProvider">
  <providers>
    <clear/>
    <add name="CustomizedProvider"
         applicationName="B-School"
         type="System.Web.Security.SqlMembershipProvider"
         minRequiredPasswordLength="5" 
         connectionStringName="SchoolConnectionString" 
         enablePasswordRetrieval="false" 
         enablePasswordReset="true" 
         requiresQuestionAndAnswer="false" 
         passwordFormat="Hashed" 
         minRequiredNonalphanumericCharacters="1"
         />
  </providers>
</membership>

And here is how my Profile Provider is configured:

<profile >
  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider"
         connectionStringName="SchoolConnectionString"
         applicationName="LCI"
         type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         />
  </providers>
  <properties>
    <add name="Id"                 type="System.Int64" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue="0"/>
    <add name="Language_Ids"       type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="Qualification_Ids"  type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="Country_Id"         type="System.Int64" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue="0"/>
    <add name="City_Id"            type="System.Int64" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue="0"/>
    <add name="Price_Id"           type="System.Int64" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue="0"/>
    <add name="Gender_Ids"         type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="StudentAge_Ids"     type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="Religion_Ids"       type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="Facility_Ids"       type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="Search_String"      type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="Compare_School_Ids" type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
    <add name="Compare_Array"      type="System.Collections.ArrayList" provider="AspNetSqlProfileProvider" allowAnonymous="true"/>
    <add name="Title_String"       type="System.String" provider="AspNetSqlProfileProvider" allowAnonymous="true" defaultValue=""/>
  </properties>
</profile>

Please tell me friends how to solve these kind of problem.

I want to know that why it hits aspnet_Profile and aspnet_Users table on every call.


Solution

  • The <profile> element in your web.config has an [optional] attribute automaticSaveEnabled. It

    Specifies whether the user profile is automatically saved at the end of the execution of an ASP.NET page. If true, the user profile is automatically save at the end of the execution of an ASP.NET page.

    Its default value is true.

    You can guess what happens then.

    Modify your <profile> element to look like something like

    <profile automaticSaveEnabled="false" ... >
    

    and you should probably be OK.

    NOTE: You will however, have to explicitly invoke ProfileBase.Save() when you want to actually store things to the backing store.