Search code examples
asp.netasp.net-membershiprolesmembership-provider

Roles.CreateRole() creates a new database inside App_Data


What could be the reason for Roles.CreateRole("admin") creating a new local database inside App_Data, if my default membership provider is set to use a connection to an actual SQL Server?

I have a connection string like this:

<connectionStrings>
  <add name="MembershipDbConnection" 
     connectionString="Server=.;Initial Catalog=aspnetdb;User Id=*;Password=*" />
</connectionStrings>

and a membership provider defined like this:

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
  <providers>
    <clear />
    <add
      name="SqlProvider"
      type="System.Web.Security.SqlMembershipProvider"
      connectionStringName="MembershipDbConnection"  <-- this is the connection
      />
  </providers>
</membership>

The weird thing is, there is an aspnetdb database (populated with tables) in my SQL Server, and if I use Membership.GetAllUsers(), I get the users in that table without problems. Login also works as expected. But Roles.CreateRole creates a new database.


Solution

  • You need to configure the Role manager section if you want to use roles. It is likely you are picking up the inherited RoleManager section that is using a different connection string.