在 MVC2 中使用 MySQL 的成员资格提供程序

发布于 2024-10-16 18:02:10 字数 2728 浏览 0 评论 0原文

我已经在这个论坛上阅读了几篇有关此问题的帖子,但似乎没有任何效果。我尝试使用最新版本的连接器 (6.3.6.0) 和 VS2010 将默认的基于 SQL Server 的提供程序替换为 MySQL 提供程序,但在访问 WSAT 中的安全部分时,我不断收到错误消息。以下是我的步骤:

1)创建一个新的mysql数据库。 2) 创建一个新的MVC2应用程序。 3)按如下方式更改 web.config:

    <connectionStrings>
     <remove name="LocalMySqlServer"/>
     <add name="LocalMySqlServer"
      connectionString="Data Source=127.0.0.1;Port=3306;Database=Sample;User id=root;Password=mysql;"
      providerName="MySql.Data.MySqlClient"/>
     <remove name="ApplicationServices"/>
     <add name="ApplicationServices"
      connectionString="Data Source=127.0.0.1;Port=3306;Database=Sample;User id=root;Password=mysql;"
       providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
    ...
    <membership defaultProvider="MySqlMembershipProvider">
     <providers>
     <clear/>
     <add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
     connectionStringName="MySqlMembershipConnection"
     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.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
         name="MySqlProfileProvider"
         applicationName="/"
         connectionStringName="MySqlMembershipConnection"
         autogenerateschema="true"/>
 </providers>
</profile>

<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
 <providers>
 <clear />
 <add connectionStringName="MySqlMembershipConnection"
  applicationName="/"
  name="MySqlRoleProvider"
  type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
  autogenerateschema="true"/>
 </providers>
</roleManager>

<machineKey validationKey="AutoGenerate" validation="SHA1"/>

当我运行 WSAT 并单击安全性时,出现此错误:

您选择的数据存储有问题。这可以是 由无效的服务器名称或 凭证或不足 允许。也可能是由于 角色管理器功能不存在 已启用。点击下方按钮即可 重定向到您可以访问的页面 选择一个新的数据存储。

以下消息可能会有所帮助 诊断问题:来源是 未找到,但部分或全部事件日志 无法搜索到。要创建 来源,您需要阅读权限 所有事件日志以确保 新的源名称是唯一的。 无法访问的日志:安全性。

谁能告诉我这个程序有什么问题吗?感谢大家!

I've read several posts in this forum about this but nothing seems to work. I'm trying to replace the default SQL Server based providers with MySQL providers using the latest version of connector (6.3.6.0) and VS2010, but I keep getting an error when accessing the Security section in WSAT. Here are my steps:

1) create a new mysql database.
2) create a new MVC2 application.
3) change web.config as follows:

    <connectionStrings>
     <remove name="LocalMySqlServer"/>
     <add name="LocalMySqlServer"
      connectionString="Data Source=127.0.0.1;Port=3306;Database=Sample;User id=root;Password=mysql;"
      providerName="MySql.Data.MySqlClient"/>
     <remove name="ApplicationServices"/>
     <add name="ApplicationServices"
      connectionString="Data Source=127.0.0.1;Port=3306;Database=Sample;User id=root;Password=mysql;"
       providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
    ...
    <membership defaultProvider="MySqlMembershipProvider">
     <providers>
     <clear/>
     <add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
     connectionStringName="MySqlMembershipConnection"
     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.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
         name="MySqlProfileProvider"
         applicationName="/"
         connectionStringName="MySqlMembershipConnection"
         autogenerateschema="true"/>
 </providers>
</profile>

<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
 <providers>
 <clear />
 <add connectionStringName="MySqlMembershipConnection"
  applicationName="/"
  name="MySqlRoleProvider"
  type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
  autogenerateschema="true"/>
 </providers>
</roleManager>

<machineKey validationKey="AutoGenerate" validation="SHA1"/>

When I run WSAT and click Security, I get this error:

There is a problem with your selected data store. This can be
caused by an invalid server name or
credentials, or by insufficient
permission. It can also be caused by
the role manager feature not being
enabled. Click the button below to be
redirected to a page where you can
choose a new data store.

The following message may help in
diagnosing the problem: The source was
not found, but some or all event logs
could not be searched. To create the
source, you need permission to read
all event logs to make sure that the
new source name is unique.
Inaccessible logs: Security.

Could anyone tell me what's wrong with this procedure? Thanks to all!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲歌长辞 2024-10-23 18:02:10

终于我成功了,我想在这里分享信息。我在 ASP.NET MVC 2 网站中使用最新版本的 Connector/Net (6.3.6)。这就是我所做的:

1)创建一个新的 MySql 数据库(或者仅使用您的数据库,如果有的话)。

2) 确保您的 machine.config 已启用 MySQLMembershpProvider 的模式自动生成。您可能知道,machine.config 通常位于 c:\windows\microsoft.net\framework[version]\config\machine.config 下。找到 MySQLMembershipProvider 条目并将属性 autogenerateschema="true" 附加到元素中。整个元素将如下所示:

<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" autogenerateschema="true"/>

3) 在您的 web.config 中(我指的是新创建的 Web 应用程序,因此如果需要,请进行更改)更改连接字符串和提供程序,以便它们引用 MySql。通常:在connectionStrings下添加:

<remove name="ApplicationServices"/>
<add name="ApplicationServices" connectionString=connectionString="server=YOURSERVER;UserId=YOURUSER;password=YOURPASSWORD;Persist Security Info=True;database=YOURDATABASE;charset=utf8" providerName="MySql.Data.MySqlClient"/>

(顺便说一句,请注意连接字符串中的 charset=utf8:这对于成员资格来说不是必需的,但如果您要使用此连接字符串来交换 Unicode 数据,则需要它:仅在您的连接字符串中定义字符集是不够的。 MySql 表字段!)。

另外,在会员资格/提供程序下...确保会员资格提供程序元素(通常类似于 add name="AspNetSqlMembershipProvider"...)connectionStringName 属性引用您上面设置的连接字符串(在我的例子中,connectionStringName="ApplicationServices") 。对配置文件和 roleManager 提供程序执行相同的操作,其应如下所示:


<profile>
  <providers>
    <clear/>
    <add type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
         name="AspNetSqlProfileProvider"
         applicationName="/"
         connectionStringName="ApplicationServices"
         autogenerateschema="true"/>
  </providers>
</profile>
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
  <providers>
    <clear />
    <add connectionStringName="ApplicationServices"
         applicationName="/"
         name="MySqlRoleProvider"
         type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
         autogenerateschema="true"/>
  </providers>
</roleManager>
<machineKey validationKey="AutoGenerate" validation="SHA1"/>

(注意 SHA1 验证!)。

4) 从 Visual Studio 启动 WSAT 并让它配置您的 MySql 数据库。它应该创建所需的所有表,并允许您创建用户和分配角色。注意表名的大小写!使用 WSAT 创建像 myaspnet_Users (而不是 myaspnet_users)这样的表,这可能会导致混乱(MySQL Workbench 似乎对此感到困惑,如果您有 2 个表,其名称仅大小写不同,则只会显示 1 个表。像 Navicat 这样的工具在这方面似乎更聪明)。最好让 WSAT 创建其表以避免这种麻烦。

最后,请记住,如果您要在某些关系中使用 my_aspnet... 表,您必须确保选择正确的 MySQL 数据库引擎,即不是 MyISAM 而是 InnoDB,否则您的外键即使设置也会被忽略。

关于这个问题我能分享的就这么多。希望这可以为其他人节省一些时间......

finally I got it working and I'd like to share the information here. I am using the latest version of Connector/Net (6.3.6) in an ASP.NET MVC 2 website. Here is what I did:

1) create a new MySql database (or just use yours if any).

2) ensure that your machine.config has enabled schema autogeneration for MySQLMembershpProvider. As you probably know, machine.config is typically placed under c:\windows\microsoft.net\framework[version]\config\machine.config. Find under the entry for MySQLMembershipProvider and append the attribute autogenerateschema="true" to the element . The whole element will look like this:

<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" autogenerateschema="true"/>

3) in your web.config (I'm referring to a newly created web application, so make your changes if required) change the connection strings and providers so that they refer to MySql. Typically: under connectionStrings add:

<remove name="ApplicationServices"/>
<add name="ApplicationServices" connectionString=connectionString="server=YOURSERVER;UserId=YOURUSER;password=YOURPASSWORD;Persist Security Info=True;database=YOURDATABASE;charset=utf8" providerName="MySql.Data.MySqlClient"/>

(BTW, notice the charset=utf8 in the connection string: this is not required for membership, but it is required if you are going to use this connection string to exchange Unicode data: it is not enough to just define the character set in your MySql table fields!).

Also, under membership / providers... ensure that the membership provider element (typically something like add name="AspNetSqlMembershipProvider"...) connectionStringName attribute refers to the connection string you set above (in my case, connectionStringName="ApplicationServices"). Do the same for profile and roleManager providers, which should look like this:


<profile>
  <providers>
    <clear/>
    <add type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
         name="AspNetSqlProfileProvider"
         applicationName="/"
         connectionStringName="ApplicationServices"
         autogenerateschema="true"/>
  </providers>
</profile>
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
  <providers>
    <clear />
    <add connectionStringName="ApplicationServices"
         applicationName="/"
         name="MySqlRoleProvider"
         type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
         autogenerateschema="true"/>
  </providers>
</roleManager>
<machineKey validationKey="AutoGenerate" validation="SHA1"/>

(Note the SHA1 validation!).

4) launch WSAT from Visual Studio and let it configure your MySql database. It should create all the tables required and let you create users and assign roles. Beware of table names casing! With WSAT tables like myaspnet_Users (not myaspnet_users) are created, and this might lead to confusions (MySQL Workbench seems to be confused by this and will show you just 1 table if you have 2 tables with their names differing only by casing. Tools like Navicat seem smarter in this respect). It's best to let WSAT create its tables to avoid this fuss.

Finally, remember that if you are going to use my_aspnet... tables in some relationships, you must make sure you select the proper MySQL database engine, i.e. not MyISAM but InnoDB, otherwise your foreign keys even if set will be ignored.

That's all I can share for this issue. Hope this might save some hours to someone else...

同尘 2024-10-23 18:02:10

也许我找到了罪魁祸首:我今天工作的电脑没有将 machine.config (对于 .net 4)配置设置为 autogenerateschema="true" (顺便说一句,上面的代码中有一个拼写错误,连接字符串名称不正确,但这只能通过在我的帖子中复制/粘贴来发生)。所以也许这对像我这样的新手很有用:记得设置 autogenerateschema="true"

无论如何,谢谢

Perhaps I found the culprit: the PC I was working today had not its machine.config (for .net 4) configuration set for autogenerateschema="true" (btw there is a typo in my code above, the connection string name is not correct, but this happened only by copy/paste in my post). So maybe this is useful for all the newcomers like me: remember to set autogenerateschema="true" in

Thanks anyway

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文