在ASP.NET MVC中使用MySQL的AccountController

nos*_*nos 7 mysql authentication asp.net-mvc

在Visual Studio中创建默认的ASP.NET MVC项目会设置一个可以注册用户的基本项目.我将如何改变这个以使用MySQL服务器而不是SQLServer?

nos*_*nos 5

现在就搞定了.

  • 安装最新的Connector/NET(当前版本为6.0.4.0)
  • 用以下内容替换web.config中的默认连接字符串:

    <add name ="ApplicationServices"connectionString ="server = 192.168.1.30; user id = thsuser; Password = thepass; database = thedatabase"providerName ="MySql.Data.MySqlClient"/>

  • 在web.config中的部分下添加以下内容(至少为6.0.4.0 mysql连接器),添加

    <add autogenerateschema ="true"connectionStringName ="ApplicationServices"enablePasswordRetrieval ="false"enablePasswordReset ="true"requiresQuestionAndAnswer ="false"requiresUniqueEmail ="false"passwordFormat ="Hashed"maxInvalidPasswordAttempts ="5"minRequiredPasswordLength ="6"minRequiredNonalphanumericCharacters =" 0"passwordAttemptWindow ="10"passwordStrengthRegularExpression =""applicationName ="/"name ="MySQLMembershipProvider"type ="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,Version = 6.0.4.0,Culture = neutral,PublicKeyToken = c5687fc88969c44d" />

  • 运行该项目,返回Visual Studio并单击解决方案资源管理器上方的ASP.NET配置按钮.

    导航到"提供程序配置" - >"为每个功能选择不同的提供程序",然后选择"MySQLMembershipProvider"

至少用于从mysql数据库注册和登录,MySQLMembershipProvider将自动生成所需的表.