The Role Manager feature has not been enabled ?

When you run ASP.NET web application, and when you try to do a Role operation such as adding a role, you might get an error message:

The Role Manager feature has not been enabled.

This error message is not from your code, it is from ASP.NET. The reason is that By default the Roles provider in machine.config and also in default web.config file it is set to disable:

    <roleManager enabled=”false”>
      <providers>
        <clear/>
        <add name=”AspNetSqlRoleProvider” type=”System.Web.Security.SqlRoleProvider” connectionStringName=”ApplicationServices” applicationName=”/” />
        <add name=”AspNetWindowsTokenRoleProvider” type=”System.Web.Security.WindowsTokenRoleProvider” applicationName=”/” />
      </providers>
    </roleManager>

So just change the setting enabled=”true” then this issue can be resolved.

If you are going to your own role provider, then you should remove the default “AspNetSqlRoleProvider” from web.config (above sameple), and then add your own, for example:

        <roleManager defaultProvider=”TRoleProvider” enabled=”true”>
            <providers>
                <clear/>
                <!–<add name=”AspNetSqlRoleProvider” type=”System.Web.Security.SqlRoleProvider” connectionStringName=”ApplicationServices” applicationName=”/” />
        <add name=”AspNetWindowsTokenRoleProvider” type=”System.Web.Security.WindowsTokenRoleProvider” applicationName=”/” />–>
                <add name=”MyRoleProvider” type=”xxxProject.myRoleProvider” connectionStringName=”xxxx” applicationName=”xxxxx” writeExceptionsToEventLog=”false”/>
            </providers>
        </roleManager>

Micorosoft’s Membership Provider Implementation Sample Code

ASP.NET membership is designed to enable you to easily use a number of different membership providers for your ASP.NET applications. You can use the supplied membership providers that are included with the .NET Framework, or you can implement your own providers.

There are two primary reasons for creating a custom membership provider.

    *      You need to store membership information in a data source that is not supported by the membership providers included with the .NET Framework, such as a FoxPro database, an Oracle database, or other data sources.
    *      You need to manage membership information using a database schema that is different from the database schema used by the providers that ship with the .NET Framework. A common example of this would be membership data that already exists in a SQL Server database for a company or Web site.

Above from MSDN

Also, they provides a very detail sample to explain how to implement a customer membership in ASP.NET

Please click here to read the sample code

Where is the MembershipProvider abstract class in .NET 4.0 ?

Question:  When I want to create a custom membership provider in asp.net 4, I can not find MembershipProvider abstract class for inheritance , where is it ?

Answer:

It is still under System.Web.Security Namespace but the assembly is System.Web.ApplicationServices but not System.Web

MembershipUser and Other Types in the System.Web.Security Namespace Have Been Moved

Implementing your own Membership Provider

ASP.NET has already provided membership providers that are included with the .NET Framework. You can use them directly for any web sites without spending your more design. However, you must feel the supplied membership providers are not convenient for your projects. Microsoft MSDN site also gave the reasons why you need to implement your own Membership provider:

There are two primary reasons for creating a custom membership provider.

    *      You need to store membership information in a data source that is not supported by the membership providers included with the .NET Framework, such as a FoxPro database, an Oracle database, or other data sources.
    *      You need to manage membership information using a database schema that is different from the database schema used by the providers that ship with the .NET Framework. A common example of this would be membership data that already exists in a SQL Server database for a company or Web site.

How to implement a Membership Provider ? What are the required stuff ?

(The following content is brief note from Microsoft MSDN)

Required Classes:

Create a class that inherits the MembershipProvider abstract class, you must implement the required members of the ProviderBase class.

The following tables list the required properties and methods that you must implement from the ProviderBase and MembershipProvider abstract classes:

Required ProviderBase Members:  Initialize method

Required MembershipProvider Members:

EnablePasswordReset property
EnablePasswordRetrieval property
RequiresQuestionAndAnswer property
RequiresUniqueEmail property
PasswordFormat property
MaxInvalidPasswordAttempts property
PasswordAttemptWindow property
ApplicationName property
MembershipProvider.CreateUser method
UpdateUser method
DeleteUser method
ValidateUser method
GetUser method
GetUser method
GetAllUsers method
GetNumberOfUsersOnline method
ResetPassword method
GetPassword method
GetUserNameByEmail method
ChangePassword method
ChangePasswordQuestionAndAnswer method
FindUsersByName method
FindUsersByEmail method
UnlockUser method

For more detail information, please read Microsoft MSDN page.