5,401,186 members and growing! (17,797 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

MySQL Membership, Role, Sitemap, Personalization Provider for ASP.Net 2.0

By onrac

Membership,Role,Sitemap and Personalization provider using Mysql
C# 2.0, VB 8.0, C#, VB, Windows, .NET, .NET 2.0, ASP.NET, MySQL, VS2005, Visual Studio, Dev

Posted: 7 Sep 2007
Updated: 7 Sep 2007
Views: 17,228
Bookmarked: 32 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
3 votes for this Article.
Popularity: 2.11 Rating: 4.43 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 33.3%
3
1 vote, 33.3%
4
1 vote, 33.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This is the implementation of Membership,Role,Sitemap,Personalization provider of ASP.Net using MySQL as backend database. This class uses the native net MySQL connector version 5.1.2

Background

This code is based on the work of J Snyman, he uses odbc to connect to MySQL, I modified it to use the native net MySQL connector version 5.1.2

Using the code

INSTRUCTION:

This is actually a C# class project, you only need to reference the compiled dll output from this project in your Web project, you can use this even if your language in your web app is vb. The provided compiled dll can be used right out of the box, but if you prefer you can compile your own.



Using the providers is really easy.

1. Create a new database on your MySQL server eg. SimpleProviders
2. Execute the following SQL statement on the newly created database

<code lang=sql>


CREATE TABLE `personalization` (
`username` varchar(255) default NULL,
`path` varchar(255) default NULL,
`applicationname` varchar(255) default NULL,
`personalizationblob` blob
);


CREATE TABLE `profiles` (
`UniqueID` int(8) NOT NULL auto_increment,
`Username` varchar(255) NOT NULL default '',
`ApplicationName` varchar(255) NOT NULL default '',
`IsAnonymous` tinyint(1) default '0',
`LastActivityDate` datetime default NULL,
`LastUpdatedDate` datetime default NULL,
PRIMARY KEY (`UniqueID`),
UNIQUE KEY `PKProfiles` (`Username`,`ApplicationName`),
UNIQUE KEY `PKID` (`UniqueID`)
);

CREATE TABLE `roles` (
`Rolename` varchar(255) NOT NULL default '',
`ApplicationName` varchar(255) NOT NULL default '',
PRIMARY KEY (`Rolename`,`ApplicationName`)
);

CREATE TABLE `sitemap` (
`ID` int(11) NOT NULL auto_increment,
`ApplicationName` varchar(255) NOT NULL default '',
`Title` varchar(255) default NULL,
`Description` text,
`Url` text,
`Roles` text,
`Parent` int(11) default NULL,
PRIMARY KEY (`ID`)
);

CREATE TABLE `users` (
`PKID` varchar(255) NOT NULL default '',
`Username` varchar(255) NOT NULL default '',
`ApplicationName` varchar(255) NOT NULL default '',
`Email` varchar(128) default NULL,
`Comment` varchar(255) default NULL,
`Password` varchar(128) NOT NULL default '',
`FailedPasswordAttemptWindowStart` datetime default NULL,
`PasswordQuestion` varchar(255) default NULL,
`IsLockedOut` tinyint(1) default '0',
`PasswordAnswer` varchar(255) default NULL,
`FailedPasswordAnswerAttemptCount` int(8) default '0',
`FailedPasswordAttemptCount` int(8) default '0',
`IsApproved` tinyint(1) NOT NULL default '0',
`FailedPasswordAnswerAttemptWindowStart` datetime default NULL,
`LastActivityDate` datetime default NULL,
`IsOnLine` tinyint(1) default '0',
`CreationDate` datetime default NULL,
`LastPasswordChangedDate` datetime default NULL,
`LastLockedOutDate` datetime default NULL,
`LastLoginDate` datetime default NULL,
PRIMARY KEY (`PKID`),
UNIQUE KEY `PKID` (`PKID`),
KEY `PKID_2` (`PKID`),
KEY `usr` (`Username`)
);

CREATE TABLE `usersinroles` (
`Username` varchar(255) NOT NULL default '',
`Rolename` varchar(255) NOT NULL default '',
`ApplicationName` varchar(255) NOT NULL default '',
PRIMARY KEY (`Username`,`Rolename`,`ApplicationName`)
);

</code>


There is an SQL file named DBStructure.sql included with the source code zip file that contains the code above
3. Open Visual Studio and create a new Website Project
4. Add a reference to the Simple.Providers.MySQL.dll
5. Make the following changes to your web.config file

1. Add the connection string to your newly created database to the connectionStrings section
eg. <add connectionString="server=localhost;database=simpleproviders;user id=<put user>;pwd=<put password>" name="SimpleProviderconnectionstring" providerName="MySql.Data.MySqlClient"/>

* Please replace the {Your username} and {Your password} entries in the connection string with your own values.


2. Under the <system.web> section add the following:
Collapse

<siteMap defaultProvider="siteMapProvider" enabled="true">
<providers>
<clear />
<add name="siteMapProvider"
type="Simple.Providers.MySQL.MysqlSiteMapProvider"
connectionStringName="SimpleProviderConnectionString"
applicationName="{Your App Name}"
description="MySQL site map provider"
securityTrimmingEnabled="true"/>
</providers>
</siteMap>
<roleManager defaultProvider="roleProvider" enabled="true"
cacheRolesInCookie="false" cookieName=".ASPROLES"
cookieTimeout="7200" cookiePath="/" cookieRequireSSL="false"
cookieSlidingExpiration="true" cookieProtection="All">
<providers>
<clear />
<add name="roleProvider"
type="Simple.Providers.MySQL.MysqlRoleProvider"
connectionStringName="SimpleProviderConnectionString"
applicationName="{Your App Name}"
description="MySQL role provider"/>
</providers>
</roleManager>
<membership defaultProvider="membershipProvider"
userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="membershipProvider"
type="Simple.Providers.MySQL.MysqlMembershipProvider"
connectionStringName="SimpleProviderConnectionString"
applicationName="{Your App Name}"
enablePasswordRetrieval="true" enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true" passwordFormat="Encrypted"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
description="MySQL membership provider"/>
</providers>
</membership>
<profile defaultProvider="profileProvider"
automaticSaveEnabled="true">
<providers>
<clear />
<add name="profileProvider"
type="Simple.Providers.MySQL.MysqlProfileProvider"
connectionStringName="SimpleProviderConnectionString"
applicationName="{Your App Name}"
description="MySQL Profile Provider"/>
</providers>
<properties>
<clear />
<!--
Add any needed attributes for profiles here.
eg. <add name="Theme" type="System.String"
defaultValue="Default"/>
-->
</properties>
</profile>
<webParts>
<personalization defaultProvider="personalizationProvider">
<providers>
<clear />
<add name="personalizationProvider"
type="Simple.Providers.MySQL.
MysqlPersonalizationProvider" connectionStringName=
"{Your Connection String Name}" applicationName="
{Your App Name}"
description="MySQL Personalization Provider/>
</providers>
</personalization>
</webParts>

/* !!! Please replace the {Your App Name} instances with a valid
application name. The application name should not contain any spaces
or special characters. !!! */

6. Everything should be set up correctly now.

Continue with the rest of your project and make sure to make use of the features provided by the above mentioned providers.

Blocks of code should be set as style "Formatted" like this:

//

// Any source code blocks look like this

//

Remember to set the Language of your code snippet using the Language dropdown.

Use the "var" button to to wrap Variable or class names in <code> tags like this.

Points of Interest

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?

History

9/7/2007 - Using mysql net connector 5.1.2 instead of ODBC.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

onrac



Occupation: Web Developer
Location: Philippines Philippines

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralCan someone provide the same example with some aspx pages.....memberMember 35865800:20 16 Jul '08  
GeneralgoodmemberDidier Stmedar4:33 4 Jul '08  
QuestionFail to test to the provider in the Asp.net ConfigurationmemberCGARRIGOS2:54 20 May '08  
QuestionHow to Order Alphabetically by the children MySqlSiteMapProvider usmemberLuizItatiba17:30 1 Apr '08  
QuestionAs Custom Menus of MYSQLSITEMAPPROVIDER, based on profiles or rolesmemberLuizItatiba10:24 1 Apr '08  
QuestionError Tool Administration of Site or ASP.NET ConfigurationmemberLuizItatiba9:57 1 Apr '08  
QuestionError WebConfigmemberLuizItatiba11:18 31 Mar '08  
QuestionUsing the driver MySqlConnector 5.0 instead of 5.1.2memberLuizItatiba13:44 26 Mar '08  
GeneralGeneral CommentsmvpJohn Simmons / outlaw programmer5:33 19 Jan '08  
QuestionODBC still present in the MysqlPersonalizationProvider.csmemberLisburn Lad5:01 8 Jan '08  
GeneralImplementation ExamplememberCreativeGolf6:54 19 Oct '07  
Generaljust Notememberibyasmo11:45 30 Sep '07  
QuestionERROR MESSAGE - SECURITYmemberKanedogg8:48 17 Sep '07  
AnswerRe: ERROR MESSAGE - SECURITY [modified]memberonrac18:18 17 Sep '07  
GeneralRe: ERROR MESSAGE - SECURITYmemberKanedogg1:47 18 Sep '07  
QuestionRe: MySQL Membership, Role Provider [modified]memberFuzziebrain16:23 13 Sep '07  
AnswerRe: MySQL Membership, Role Providermemberonrac18:20 17 Sep '07  
Generalgood effortmemberlxwde15:52 10 Sep '07  
Generalnicemembermascix14:46 10 Sep '07  
GeneralSubSonicmemberZachary Owens4:04 8 Sep '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 Sep 2007
Editor:
Copyright 2007 by onrac
Everything else Copyright © CodeProject, 1999-2008
Web17 | Advertise on the Code Project