如何设置ASP.NET MVC 2与MySQL? [英] How do I setup ASP.NET MVC 2 with MySQL?

查看:168
本文介绍了如何设置ASP.NET MVC 2与MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能安装ASP.NET MVC 2与MySQL数据库工作?

Is it possible to setup ASP.NET MVC 2 to work with a MySQL database?

推荐答案

我假设你有Visual Studio专业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.


  1. 如果您还没有,在时间的.NET (6.2.2.0安装的MySQL Connector这写)

  2. 可选:安装的MySQL GUI工具

  3. 如果您还没有安装<一href=\"http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c9ba1fe1-3ba8-439a-9e21-def90a8615a9\">MVC 2 RTM ,或者更好,使用微软的 Web平台安装。 (更新: MVC 2现在已经发布了一段时间)

  4. 创建一个空的MySQL数据库。如果你不想用MySQL root用户帐户(不安全)来访问你的应用程序,创建用户帐户并指定相应的权限(这写的范围之内)。

  5. 创建在Visual Studio中一个新的MVC 2应用程序

  6. 在MVC 2的应用程序,参考MySql.Web.dll。它要么是在你的GAC或文件夹中MySQL连接器的安装程序把它。

  7. 修改你的web.config的连接字符串部分:

  1. If you haven't, install MySQL Connector for .NET (6.2.2.0 at the time of this write-up)
  2. Optional: install MySQL GUI Tools
  3. If you haven't, install MVC 2 RTM, or better yet, use Microsoft's Web Platform Installer. (UPDATE: MVC 2 has now been released for quite some time)
  4. Create an empty MySQL database. If you don't want to access your application with the MySQL root user account (insecure), create a user account and assign the appropriate privileges (outside the scope of this write-up).
  5. Create a new MVC 2 application in Visual Studio
  6. In the MVC 2 app, reference MySql.Web.dll. It will either be in your GAC, or in the folder that the MySQL Connector installer put it.
  7. 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>


在这一点上,你应该能够运行应用程序并具有默认的A​​SP.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布里奇沃特的博客是得到这个工作是必不可少的。荣誉,内森。寻找配置工具标题一半下来的页面。

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 [路径\\为\\ 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!

这篇关于如何设置ASP.NET MVC 2与MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆