Search code examples
c#asp.netvs-web-application-project

How to add properties to MembershipProvider


I want to extend additional user registration fields, and other tutorial suggested the way to do this is to use the profile-properties. (?)

So I add a section to the Web.config file, as shown below ( tag), and I expected Profile to be available by intellisense in the .cs files, but it's not..

So how to make this work? And are there better solutions to this?

Btw, the tutorial was this one.

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>

<membership>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
  </providers>
</membership>

<profile>
  <properties>
    <add name="Age"/>
    <add name="Gender" />
  </properties>

  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
  </providers>

</profile>

Solution

  • Have a look at ProfileProvider instead. It's designed to extend additional properties against the MembershipUser.

    You can then strong type access to the Profile. If your are using the Web site project this is code generated for you from your config settings. Web Application project you need to do this manually, or use external tools. This article has some useful info.