ASP.Net MVC 使用MySQL 【转】
2015-07-06 22:10
591 查看
ASP.Net MVC 使用MySQL
(2012-04-10 15:49:50)转载▼
标签: |
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.
If you haven't, install MySQL Connector for .NET (6.2.2.0 at the time of this write-up)
Optional: install MySQL GUI Tools
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)
Cr
4000
eate 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).
Create a new MVC 2 application in Visual Studio
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.
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.
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.
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.
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>
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.
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.
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.
There you have it, ASP.NET MVC 2 running over MySQL. Cheers!
相关文章推荐
- ASP.NET MVC与Sql Server交互,把字典数据插入数据库
- Asp.Net Ajax4.5 未知的服務器標記 問題
- ASP.NET MVC与Sql Server交互, 插入数据
- ASP.NET MVC与Sql Server建立连接
- 【回味无穷】ASP.NET内部控件
- ASP.NET动态添加用户控件的方法
- Asp.net Vnext IValueProvider
- 关于在asp.net中的调试
- aspx 体现mvc 模式的增删改查
- 解密aspx与aspx.cs的关系
- ASP.Net核心对象之context.Server对象几个常用方法
- Web服务器和ASP.Net
- asp了解
- 第1章 ASP.NET4.0开发技术概述
- Picture Aspect Ratio
- ASP.NET 为什么要有 MVC
- ASP.NET分页
- asp.net webapi 多文件上传
- 大型高性能ASP.NET系统架构设计
- ABP(现代ASP.NET样板开发框架)主题线下交流会(上海)开始报名了!