A mysql membership and role provider for asp.net 2.0

本文提供了一套详细的MySQL数据库安装与配置指南,包括下载MySQL.NET Connector、创建必要的数据库表、配置web.config文件等内容。此外还提供了性能优化及错误修复等实用信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先请点这里下载最新的操作MYSQL的程序集以及本文章的源代码:

Download

download the code here.

 

Setup

  1. Get the latest MySQL .NET Connector for .NET v2.0 (make sure you use the binaries for .NET v2.0). Copy the file in your ~/bin folder.
  2. Create the tables. The sql commands may change from a mySQL version to another, these following commands should be compatible with mySQL 4.1.

    # Table: 'roles'

    #

    CREATE

    TABLE `roles` (

    `

    Rolename` varchar(255) collate latin1_general_ci NOT NULL default '',

    `

    ApplicationName` varchar(255) collate latin1_general_ci NOT NULL default '',

     

    )


     

    # Table: 'users'

    #

    CREATE

    TABLE `users` (

    `

    PKID` varchar(36) collate latin1_general_ci NOT NULL default '',

    `

    Username` varchar(255) collate latin1_general_ci NOT NULL default '',

    `

    ApplicationName` varchar(100) collate latin1_general_ci NOT NULL default '',

    `

    Email` varchar(100) collate latin1_general_ci NOT NULL default '',

    `

    Comment` varchar(255) collate latin1_general_ci default NULL,

    `

    Password` varchar(128) collate latin1_general_ci NOT NULL default '',

    `

    PasswordQuestion` varchar(255) collate latin1_general_ci default NULL,

    `

    PasswordAnswer` varchar(255) collate latin1_general_ci default NULL,

    `

    IsApproved` tinyint(1) default NULL,

    `

    LastActivityDate` datetime default NULL,

    `

    LastLoginDate` datetime default NULL,

    `

    LastPasswordChangedDate` datetime default NULL,

    `

    CreationDate` datetime default NULL,

    `

    IsLockedOut` tinyint(1) default NULL,

    `

    LastLockedOutDate` datetime default NULL,

    `

    FailedPasswordAttemptCount` int(11) default NULL,

    `

    FailedPasswordAttemptWindowStart` datetime default NULL,

    `

    FailedPasswordAnswerAttemptCount` int(11) default NULL,

    `

    FailedPasswordAnswerAttemptWindowStart` datetime default NULL,

     

    )

    PRIMARY KEY (`PKID`) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;



    # Table: 'usersinroles'

    #

    CREATE

    TABLE `usersinroles` (

    `

    Username` varchar(255) collate latin1_general_ci NOT NULL default '',

    `

    Rolename` varchar(255) collate latin1_general_ci NOT NULL default '',

    `

    ApplicationName` varchar(255) collate latin1_general_ci NOT NULL default '',

     

    )

    PRIMARY KEY (`Username`,`Rolename`,`ApplicationName`) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
    PRIMARY KEY (`Rolename`,`ApplicationName`) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
  3. Unzip the files to your the root folder of you app.
  4. Configuration : Open and change the web.config file :
    1. Change the connection string : Look for the node <connectionStrings> :  
      • Database : this is the name of the database where you have previously created the tables
      • Data Source : the IP of your mysql server
      • User Id : your mysql username
      • Password : your mysql password
    2. Optional steps :
      • change the value of encryptionKey to a random hexadecimal value of your choice 
      • change the value of applicationName, you have two lines to change, both values should be the same.
  5. Test : load the page /Examples/Default.aspx or /Examples/CreateUser.aspx in your browser
  6. Leave a comment or a bug report under the comments section on this page.
  7. Make a small contribution here or here

Change log

  • MUCH better performance.
  • encryptionKey is now in web.config
  • Bug fix : GetUser() : the reader is now properly closed
  • Bug fix : GetAllUsers() : failed everytime because one parameter was missing
  • Bug fix : FindUsersByEmail(string, int, int, out int) : failed everytime because one parameter was missing
  • event logging removed
    • it was unusable anyway on a shared hosting environnement
    • it's much easier to find a bug when the app throws plain exceptions
  • The distribution is now in a binary (some people did not know what to do with the source files)
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值