是否可以设置 ASP.NET MVC 2 以使用 MySQL 数据库?
Is it possible to setup ASP.NET MVC 2 to work with a MySQL database?
我假设您拥有 Visual Studio Professional 2008,可以访问 MySQL 服务器的实例,并且具有中到高级的开发经验.这可能适用于 VS2008 网络版,但完全不确定.
I'm assuming that you have Visual Studio Professional 2008, have access to an instance of MySQL server, and have moderate to advanced development experience. This MAY work with VS2008 Web edition, but not at all sure.
修改 web.config 的连接字符串部分:
Modify the connection strings portion of your web.config:
<connectionStrings>
<remove name="LocalMySqlServer"/>
<add name="MySqlMembershipConnection"
connectionString="Data Source=[MySql server host name];
userid=[user];
password=[password];
database=[database name];"
providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
8.
修改 web.config 的成员资格部分:
Modify the membership portion of your web.config:
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear/>
<add name="MySqlMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web,
Version=6.2.2.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>
9.
修改 web.config 的角色管理器部分:
Modify the role manager portion of your web.config:
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
<providers>
<clear />
<add connectionStringName="MySqlMembershipConnection"
applicationName="/"
name="MySqlRoleProvider"
type="MySql.Web.Security.MySQLRoleProvider, MySql.Web,
Version=6.2.2.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true"/>
</providers>
</roleManager>
10.
修改 web.config 的配置文件部分:
Modify the profile portion of your web.config:
<profile>
<providers>
<clear/>
<add type="MySql.Web.Security.MySQLProfileProvider, MySql.Web,
Version=6.2.2.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d"
name="MySqlProfileProvider"
applicationName="/"
connectionStringName="MySqlMembershipConnection"
autogenerateschema="true"/>
</providers>
</profile>
此时,您应该能够运行应用程序并在浏览器中显示默认的 ASP.NET MVC 2 主页.但是,最好先运行 ASP.NET Web 配置工具(在 Visual Studio 顶部菜单中:项目 -> ASP.NET 配置).工具启动后,检查每个选项卡;没有错误 = 一切顺利.
At this point, you ought to be able to run the app and have the default ASP.NET MVC 2 home page come up in your browser. However, it may be a better idea to first run the ASP.NET Web configuration Tool (in Visual Studio top menus: Project -> ASP.NET Configuration). Once the tool launches, check out each of the tabs; no errors = all good.
Nathan Bridgewater 的博客 对实现这一目标至关重要.荣誉,内森.寻找页面中间的配置工具".
The configuration tool at Nathan Bridgewater's blog was essential to getting this working. Kudos, Nathan. Look for the "Configuration Tool" heading half way down the page.
我在这里发布的 MySql.web.dll 上的公钥令牌应该不会很快改变.但是,如果您怀疑通过复制和粘贴或其他方式产生了错误的令牌字符串,只需使用 Visual Studio 命令行运行:sn -T [Path\to\your.dll]"以获得正确的公钥令牌.
The public key token on the MySql.web.dll that I've posted here ought not change any time soon. But in case you suspect a bad token string from copying and pasting or whatever, just use the Visual Studio command line to run: "sn -T [Path\to\your.dll]" in order to get the correct public key token.
你知道了,ASP.NET MVC 2 在 MySQL 上运行.干杯!
There you have it, ASP.NET MVC 2 running over MySQL. Cheers!
这篇关于如何使用 MySQL 设置 ASP.NET MVC 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!