在Asp.net中利用MySQL数据库进行验证

数据库 MySQL
本文主要向大家讲述的是在Asp.net中利用MySQL数据库进行验证的实际操作步骤,以下就是文章的主要内容描述,望你会从中得到自己想要的东西。

以下的文章主要向大家描述的是在Asp.net中利用MySQL数据库进行验证 ,一直想把Asp.net与MySQL数据库结合起来,包括使用.net自带的 providers、membership、roles等登录验证,因为MsSql太大了,个人使用没有必要。

在网上Google了半天,没有发现有价值的东西,大都是些如果读取、写入MySQL数据等,而且网上还有很多误导信息,要通过一些开源的插件(类)来实现。其实,MySQL数据库官方的 MySQL-connector-net 早在5.1版本就支持asp.net authorization 了,可以在官方网站和google却很少有配置教程,最终我在一土耳其网站上找到了详细的配置说明,现整理如下:

1、下载 MySQL Connector,我下载的是5.2.5,地址:http://dev.MySQL.com/downloads/connector/net/5.2.html,要用安装版本,这样在安装过程中会对machine.config 、vs2008 等进行一些默认配置,省去了手动配置的麻烦。

2、在网站web.config文件上添加ConnectionString

 

  1. <connectionStrings>   
  2. <remove name="LocalMySQLServer"/>   
  3. <add name="LocalMySQLServer" connectionString="server=localhost; 
    user id=root; password=toor; persist security info=true; database=dorknozzle;
    "
     providerName="MySQL.Data.MySQLClient"/>   
  4. </ connectionStrings> 

3、把MySQL.Data.dll文件复制到网站bin文件夹并添加引用

4、在machine.config (c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config)中添加 autogenerateschema="true" ,自动生产相关表格结构,如下:

 

  1. <membership>   
  2. <providers>   
  3. <add name="MySQLMembershipProvider" autogenerateschema="true" type="MySQL.
    Web.Security.
    MySQLMembershipProvider, MySQL.Web, Version=5.2.2.0, ... />   
  4. </providers>   
  5. </membership> 

5、在Vistual stuido 2008中打开Asp.net 网站管理工具(项目 > ASP.NET 配置),在“提供程序”页面选择“为每项功能选择不同的提供程序(高级)”,接下来在“成员资格提供程序”中选择MySQLMembershipProvider ,在“角色提供程序”中选择MySQLRoleProvider 。

6、接下来就是享受Asp.net 和 MySQL数据库 带来的乐趣吧!

测试过程中出现的以下错误再也不见了(英文版出错信息,中文版出错信息没有保存):

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: Unable to initialize provider. Missing or incorrect schema.(c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line 145)

 

 

以上的相关内容就是对在Asp.net中利用MySQL数据库进行验证的介绍,望你能有所收获。

【编辑推荐】

  1. MySQL 常用语句的基本用法的介绍
  2. 解决MySQL远程访问不允许得个好用方案
  3. 解决MySQL无法远程访问的3方案
  4. PHP和MySQL存储过程的实例演示
  5. MySQL编码机制与乱码
责任编辑:佚名 来源: cnblogs
相关推荐

2010-05-25 08:49:33

连接MySQL

2009-07-20 17:03:55

批量插入数据ASP.NET

2010-06-07 14:34:49

连接MySQL 数据库

2009-08-04 15:02:18

ASP.NET数据验证

2009-07-28 14:16:31

ASP.NET与MyS

2009-04-17 09:36:25

ASP.NETOracleWinform

2009-07-28 17:36:21

ASP.NET数据库连

2009-07-31 09:57:47

ASP.NET数据库缓

2009-02-23 15:20:03

SQL Server数据库ASP.NET

2009-08-05 15:40:49

ASP.NET连接数据

2009-08-11 12:52:05

ASP.NET数据库程

2009-07-29 09:59:10

ASP.NET For

2009-07-29 09:12:31

ASP.NET数据库连

2009-08-04 14:52:33

Visual Web ASP.NET

2009-08-05 09:38:28

SQL Server数

2009-08-05 16:50:09

ASP.NET For

2009-07-27 17:25:53

ASP.NET验证控件

2009-08-05 16:17:29

ASP.NET For

2009-08-04 15:20:59

ASP.NET数据验证数据验证控件

2009-09-18 10:20:26

PRG数据验证
点赞
收藏

51CTO技术栈公众号