This is a two part article that will teach you how to create an ASP.Net web application with Membership and Role Provider and integrate Facebook connect to it. We will be using Visual Studio 2008 on this one.
The first part is creating/setting up Membership and Role Provider to your web application. OK then let us start up.
Setting up ASP.Net Membership and Role Provider
First we need to create a website and on our example let us just call it “MyWebsite”.
Then setup our Database to store our users and roles. On this one we just simply create a Database and name it “MyDatabase”. Then we open up our Visual Studio 2008 Command Prompt Window and typed in “aspnet_regsql.exe”. This is a wizard tool that let us create necessary tables for our Database. Now on the wizard we just put in our Server credentials (I am just using Windows Credentials) and choose the Database where we want to create the tables. After the wizard is completed our Database is all setup now.
Let us go back to our website and open up the web.config file. Let us add a new Connection String that is pointing to our Database.
On the web.config it would looked liked this:
<connectionStrings> <add name="MyConnectionString" connectionString="Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>
Find the system.web element and inside of it find and change the authentication mode to Forms just like the code below.
<authentication mode="Forms"> <forms defaultUrl="Default.aspx" loginUrl="Login.aspx" /> </authentication>
Then add this code inside the system.web element.
<roleManager enabled="true" defaultProvider="SqlProvider"> <providers> <clear/> <add connectionStringName="MyConnectionString" name="SqlProvider" type="System.Web.Security.SqlRoleProvider"/> </providers> </roleManager> <membership defaultProvider="SqlProvider"> <providers> <clear/> <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MyConnectionString" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Encrypted" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" enablePasswordRetrieval="true" enablePasswordReset="true"/> </providers> </membership>
You can check out this link for the information of the membership element. And this link too for the roleManager element.
Then this code as well
<machineKey validationKey="put your validation key here"
decryptionKey="put your decryption key here"
validation="SHA1"
decryption="Auto"/>
You can check out this link for the information of the machineKey element. I am using a string for my validationkey and decryption key. I found this interesting ASP.Net machineKey Generator. Just copy and paste the generated keys to your code. Now create a Login page, mine I called “Login.aspx”. Then drag a Login control over it. Our login page should be looked like this.
Now create a Login page, mine I called “Login.aspx”. Then drag and drop a Login control over it. Our login page should looked liked the code below.
<form id="form1" runat="server"> <div> <asp:Login ID="Login1" runat="server"> </asp:Login> </div> </form>
Now let us create an initial user (or an admin for example) and create some roles too. We can simply manage the users and roles of our website simply by going to the top menu and choose Website -> ASP.NET Configuration. This will lead us to Site Administration Tool page.

Go to the Security tab then “Create or Manage Roles”. Now let us create an “Admin” and “Member” roles.
Then let us create an Admin user account. Let us just make the username as “admin”, password is “password”, and email is “your@mail.com”. Then set the role as Admin. Now we have an admin account.
Now our website is already set up for Membership and Role Provider. You can compile and build it.
Next article is Part 2: Integration of Facebook Connect

