Configuring MOSS 2007 Anonymous site to use ASP.NET Membership Provider

nHi again in this anonymous site series..

n

n

n

nIn my previous post I explained steps about how to create anonymous web site using SharePoint existing site. So in this post I am going to make use of out of the box ASP.NET Membership Provider and it to anonymous site which we created. (This is easy one)

n

n

n

nSo very first step is to have ASPNET db in SQL Server, and for this we are going to use the traditional ASP.NET way with popular command aspnet_regsql

n

n

n

n1. Open visual studio command prompt and type in command aspnet_regsql, you will see ASP.NET Sql Server setup wizard, click next and select configure SQL Server for application services.

n

n

n

nEnter Database Server name and keep database name as <default> in dropdown (this will create db with name aspnetdb in SQL Server), click finish on next screen

n

n
n

n

n2. Once aspnetdb database is created in SQL Server, then next step is to make use of this db.

n

n

n

nBrowse to Central Administration site and click on Application Management tab. Find and click on Authentication Providers, select Internet zone. Change Authentication type to Forms , and enter Membership Provider Name as AspNetSqlMembershipProvider and Role Manager Name as AspNetSqlRoleProvider. Click on save.

n

n

n

n

n

n

n

n3. Now we have configured anonymous application to use Forms authentication, next step is to specify Membership provider and role manager entries in web.config file of anonymous web site

n

n

n

nAdd following entries to web.config file

n

n
n
 

n

n

n<membership>

n

n  <providers>

n

n   <add

n

nname=AspNetSqlMembershipProvider type=System.Web.Security.SqlMembershipProvider,System.Web,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a connectionStringName=LocalSqlServer

n

nenablePasswordReset=true

n

nrequiresQuestionAndAnswer=true

n

npasswordFormat=Hashed

n

napplicationName=/

n

n/>

n

n  </providers>

n

n</membership>

n

n

n

n<roleManager>

n

n  <providers>

n

n    <remove name=AspNetSqlRoleProvider />

n

n

n

n<add

n

nname=AspNetSqlRoleProvider type=System.Web.Security.SqlRoleProvider,System.Web,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a connectionStringName=LocalSqlServer

n

nrole=SignedInClient

n

napplicationName=/

n

n/>

n

n   </providers>

n

n</roleManager>

n

n

n

n<connectionStrings>

n

n   <remove name=LocalSqlServer />

n

n

n

n<add name=LocalSqlServer

n

nconnectionString=Data Source=DbServer;Initial Catalog=aspnetdb;

n

nIntegrated Security=True

n

nproviderName=System.Data.SqlClient />

n

n</connectionStrings>

n

n

n

nConnection string is required for application to know about aspnetdb.
n

n

n

n4. Now , to register users with anonymous site you can use out of box ASP.NET user registration wizard control and Login control , so there are two ways to achieve this

na. You can create your custom page layouts and add those ASP.NET controls to page layouts like this
n
n

nFor Login Page:

n

n<asp:Login runat=”server” ID=”Login1″ DestinationPageURL=”/Pages/Default.aspx” CreateUserText=”Create User” CreateUserUrl=”/Pages/Registration.aspx”></asp:Login>

n

nFor Registration Page:

n

n<asp:CreateUserWizard ID=”CreateUserWizard2″ runat=”server” ContinueDestinationPageUrl=”/Pages/Default.aspx”>

n

n            <WizardSteps>

n

n       <asp:CreateUserWizardStep ID=”CreateUserWizard1″ runat=”server” />

n

n       <asp:CompleteWizardStep ID=”CompleteWizardStep1″ runat=”server” />

n

n            </WizardSteps>

n

n </asp:CreateUserWizard>

n
n
nb. Or you can create your web parts wrapping OOB ASP.NET controls and add them to your site
n
n

n

nLogin WebPart :

n

n             protected override void CreateChildControls()

n

n            {

n

n            try

n

n            {

n

n                base.CreateChildControls();

n

n                Login loginControl = new Login();

n

n                loginControl.DestinationPageUrl = “/Pages/Default.aspx”;

n

n                loginControl.CreateUserUrl = “/Pages/Registration.aspx”;

n

n                this.Controls.Add(loginControl);

n

n            }

n

n            catch (Exception ex)

n

n            {

n

n               

n

n   }

n

nRegistration WebPart:

n

nprotected override void CreateChildControls()

n

n        {

n

n            try

n

n            {

n

n                base.CreateChildControls();

n

n                CreateUserWizard cwz = new CreateUserWizard();

n

n                cwz.ContinueDestinationPageUrl = “/Pages/Default.aspx”;

n

n                this.Controls.Add(cwz);

n

n

n

n            }

n

n            catch (Exception ex)

n

n            {

n

n               

n

n            }

n

n        }

n

n

n

n

nNote: there are many properties of these controls which you can configure as your need

n

n

n

n

n

n

n

n5. Once you have set up all these things and have your custom login page then , change default login page of anonymous site using IIS Manager like this

n

n

n

nFind anonymous site in IIS > find authentication in features view >right click on Forms Authentication> click edit > change login url

n

n

n

n

n

n

n

n

n

nAbove all settings worked pretty perfectly for me (at least 🙂 )

n

n

n

nReference best Links: This and This

Leave a Comment