首先请点这里下载最新的操作MYSQL的程序集以及本文章的源代码:
Download
Setup
- 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.
- 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; - Unzip the files to your the root folder of you app.
- Configuration : Open and change the web.config file :
- 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
- 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.
- Change the connection string : Look for the node <connectionStrings> :
- Test : load the page /Examples/Default.aspx or /Examples/CreateUser.aspx in your browser
- Leave a comment or a bug report under the comments section on this page.
- 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)