配置ASP.NET标识以使用MySQL

时间:2014-06-16 19:17:58

标签: mysql asp.net visual-studio-2013

我正在使用Visual Studio 2013开发Web表单应用程序。我选择了身份验证:个人用户帐户。我希望包括ASP Identity在内的应用程序能够使用MySQL。

我添加了对MySql.Data,MySql.Data.Entity.EF6,MySql.Web的引用,并对Web.config进行了以下更改:

<connectionStrings>
    <add name="EkoPayMaster.Properties.Settings.EkoPayMasterConnectionString" connectionString="server=localhost;user id=root;persistsecurityinfo=True;database=paymaster" />
</connectionStrings>

    <membership defaultProvider="MySqlMembershipProvider">
      <providers>         
        <clear />
        <add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web" connectionStringName="EkoPayMasterConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" autogenerateschema="true" />
      </providers>
    </membership>
    <profile>
      <providers>           
        <clear />
        <add type="MySql.Web.Security.MySqlProfileProvider, MySql.Web" name="MySqlProfileProvider" applicationName="/" connectionStringName="EkoPayMasterConnectionString" autogenerateschema="true" />
      </providers>
    </profile>
    <roleManager enabled="true" defaultProvider="MySqlRoleProvider">
      <providers>
        <clear />
        <add connectionStringName="EkoPayMasterConnectionString" applicationName="/" name="MySqlRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web" autogenerateschema="true" />
      </providers>
    </roleManager>

  <entityFramework>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient"></remove>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0" />
    </DbProviderFactories>
  </system.data>

当我运行应用程序时,我能够注册用户并登录。但是,ASP Identity不会创建必要的用户表是MySql数据库。

如何让应用程序将表/用户信息添加到MySql中,我需要做什么?

1 个答案:

答案 0 :(得分:1)

首先,据我所知,您必须在所有提供商的connectionStringName属性中使用您在connectionStrings / add name中提供的完全相同的连接字符串名称。