我是 MVC 和 MySQL 的新手。我在带有 MySQL 的 MVC 4 中有代码优先应用程序。
public class Category
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public virtual IEnumerable<Product> Products { get; set; }
}
public class Product
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public DateTime CreateDate { get; set; }
public int CategoryID { get; set; }
public virtual Category Category { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
}
在 web.config 中:
<connectionStrings>
<add name="MyContext" connectionString="server=localhost; User Id=root; Pwd=mypass; Persist Security Info=True; database=catalogue" providerName="MySql.Data.MySqlClient " />
</connectionStrings>
因此,这会在 mysql 中创建目录数据库。但我也想使用mysql 的成员资格。注册、创建用户和管理他们的角色。例如,使用 mvc4 的默认 AccountModels
我将此代码添加到 web.config:
<system.web>
<membership defaultProvider="MySQLMembershipProvider">
<providers>
<clear />
<remove name="MySQLMembershipProvider" />
<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="MySQL default application" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enablePasswordRetrieval="True" enablePasswordReset="True" requiresQuestionAndAnswer="False" requiresUniqueEmail="False" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
</providers>
</membership>
<profile defaultProvider="MySQLProfileProvider">
<providers>
<clear />
<remove name="MySQLProfileProvider" />
<add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="Profiles" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="False" autogenerateschema="True" />
</providers>
</profile>
<roleManager enabled="false" defaultProvider="MySQLRoleProvider">
<providers>
<clear />
<remove name="MySQLRoleProvider" />
<add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="Project Roles" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" />
</providers>
</roleManager>
</system.web>
运行应用程序时出现此错误:
我忘记了哪一步?我不能使用会员。
(抱歉英语不好)