ASP.Net MVC 使用MySQL 【转】

转载 2015年07月06日 22:10:19

ASP.Net MVC 使用MySQL

 (2012-04-10 15:49:50)
标签: 

mvc

 

mysql

 

连接mysql

 

配置web.config

 

it

 

成功连通MySQL,不过当时比较简单,没有配置到这么多地方。

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. 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.

    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 项目中使用 WebForm

在 ASP.NET MVC 项目中使用 WebForm ASP.NET MVC和WebForm各有各的优点,可能需要同时使用ASP.NET MVC和WebForm...

构建MySql的ASP.NET MVC5应用的演练(一)

构建MySql的ASP.NET MVC5应用的演练     1 概述     目标:第一、使用MySql数据库,建立一个使用构建MySql的ASP.NET MVC5应用的演练的应用,实现用户和角色...

ASP.NET MVC4整合NHibernate,FluentNHibernate,MySQL数据库的应用

Models层的类: public abstract class Entity { public virtual int Id { get; set; } } public ...
  • WuLex
  • WuLex
  • 2016年07月31日 23:50
  • 777

ASP.NET MVC5+MySql使用ASP.NET 身份验证

ASP.NET MVC5+MySql使用ASP.NET 身份验证     1    概述 目标:使用MySql数据库,建立一个使用ASP.NET 身份验证的应用,身份验证的数据库为指定的MySql数...

[转]ASP.Net MVC开发基础学习笔记(3):Razor视图引擎、控制器与路由机制学习

【出处】http://www.cnblogs.com/edisonchou/p/3923475.html 关于机制的介绍,讲得不错,觉得可以参考着学习一下 1.1 千呼万唤始出来的MVC3.0  ...
  • fynjy
  • fynjy
  • 2015年07月20日 14:25
  • 275

asp.net mvc 页面跳转及页面组合

页面跳转 使用MVC新的 RedirectToAction return RedirectToAction("Index","Home");//跳转到首页。 第一个参数是action 的名字,第二个参...

ASP.NET MVC Framework体验(4):控制器(转)

概述 在MVC中,Controller用来处理和回应用户的交互,选择使用哪个View来进行显示,需要往视图中传递什么样的视图数据等。ASP.NET MVC Framework中提供了IControl...
  • yan0639
  • yan0639
  • 2013年11月01日 18:02
  • 301

转:ASP.NET MVC:窗体身份验证及角色权限管理示例

前言   本来使用Forms Authentication进行用户验证的方式是最常见的,但系统地阐明其方法的文章并不多见,网上更多的文章都是介绍其中某一部分的使用方法或实现原理,而更多的朋友则发...

(转)理解ASP.NET MVC执行过程

向基于ASP.NET MVC的Web程序发送请求首先传递一个 UrlRoutingModule 对象,这是一个HTTP模块。这个模块解析请求并执行路由选择。UrlRoutingModule 对象选择第...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ASP.Net MVC 使用MySQL 【转】
举报原因:
原因补充:

(最多只允许输入30个字)