You are on page 1of 19

Setting up ASP.Net 2.

0 Forms Authentication User and Role Data Source


This section explains creation of database which is used to store user's information such as
credentials and roles which is used for Form Authentication. This section also explains the
configuration of Membership and Role providers in the web.config file and creation of users
using ASP.Net configuration wizard. This article shows creating a user and which will be
used for testing Form Authentication later.

Create Database
To create database, Microsoft has provided a tool/utility called aspnet_regsql.exe that
creates a database for us. This utility can be found in %windir
%\Microsoft.NET\Framework\v2.0.50727 folder. Please see the image below:

Executing aspnet_regsql.exe file will open ASP.Net SQL Setup wizard that will walk through
creating the ASP.Net 2.0 database. I have added the database name as SPSFormAuth and
configured it for windows authentication. Please see the image below:
Click on Next button. Please see the image below:
Select Configure SQL Server for application services option and click Next button.
Please see the image below:
It will show the summary screen and click the Next button. Please see the image below:
Click Next button. Now the database SPSFormAuth is created successfully. Please see the
image below:
Configure Membership and Role Providers
In the previous section, database is created successfully. Now we need to add a user in to
database. Using ASP.Net Configuration Wizard, users can be added the database. This can
be achieved by creating web site that will allow us to add the users and roles and also
ensure the database connection strings, membership and role providers are correctly
configured before we bring SharePoint in to equation.
Below steps explains creating web site and configuring membership and role providers and
executing ASP.Net Configuration Wizard.

1) Open Visual Studio 2005 and select File   New  Web Site. In the New Web Site
dialog, select the ASP.Net Web Site template and enter the location to store the web
site files. Please see the image below:
2) Add a new web.config file to web site project. Please see the image below:
3) By default, you will see a <connectionStrings/> node within <configuration> node.
Specify the connection string to the database which has been created in the previous
section. Please use the example given below:

<connectionStrings>
<add name="FBA_SqlConnectionString" connectionString="Data
Source=MOSS2007\OFFICESERVERS;Integrated Security=SSPI;Initial
Catalog=SPSFormAuth;" />
</connectionStrings>

4) After setting up the connection string, we need to specify the membership and role
providers in the web.config file. In this article, I am using ASP.Net SQL Membership and
Role providers. So specify the provider's information within the <system.web> tag.
Please use the example given below:

<!-- Membership Provider -->

<membership defaultProvider="FBA_MembershipProvider">
<providers>
<add connectionStringName="FBA_SqlConnectionString" applicationName="/"
enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
passwordFormat="Hashed" maxInvalidPasswordAttempts="5"
passwordAttemptWindow="10"
name="FBA_MembershipProvider"
type="System.Web.Security.SqlMembershipProvider" />
</providers>
</membership>
<!-- Role Provider -->

<roleManager enabled="true" defaultProvider="FBA_RoleProvider">


<providers>
<add connectionStringName="FBA_SqlConnectionString" applicationName="/"
name="FBA_RoleProvider" type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>

5) Save web.config file and launch the ASP.Net Configuration Wizard by clicking
on Website  ASP.Net Configuration. Please see the image below:
6) Set the authentication type in the above wizard. To do this, click Security link. In
the Security tab, under Users section, click Select authentication type link.
Select From the internet option and press Done button which is available in the
bottom right corner. By selecting this option, which means that site will use form
authentication to identify users. Please see the image below
7) To test the membership and role providers, click on Provider tab. In the Provider tab,
click on Select a different provider for each feature (advanced) link. Select right /
correct membership and role provider and click Test link to ensure that providers are
communicating to right database.

At this point, we configured web.config file with connection string and providers
information. Also we tested the providers with the database. Next section will explain
adding users to database.

Create a User
1) To add users, click on Security tab. In Security tab, under Users section, click Create
user link. Here I am adding user as testFBA and password as password which will be
used for testing form authentication later. Please see the image below:

Creating Web Applications


This section explains creating web application using SharePoint Central Administration. In
this article I am creating two, sites; one is extranet site which will be used by the content
owners and configured to windows authentication. Another site is internet site specifically
for internet users and configured to form authentication. Below section explains creating of
two sites.
Creating extranet IIS Web site

1) Click Start  All Programs  Microsoft Office Server  Central Administration.


2) In the Application Management tab, under SharePoint Web Application
Management section, click Create or extend Web application link.
3) In Create or Extend Web Application page, click Create a new Web
Application link. Provide the information to create new web application and
click OK button. Please see the image below.
4) Create site under the above web application. To do this, in Application
Management tab, under SharePoint Site Management section, click Create site
collection link.
5) In Create Site Collection page, select the web application which have been created in the
previous step and provide other information to create the site and click OK button.
Please see the image below.
Now we created the web application and site successfully. Next section explains creating
internet site.

Creating internet IIS Web site

This section explains extend our web application to another internet site which has been
created in the previous sections. This site is for anonymous or internet users.

1) Click Start  All Programs  Microsoft Office Server  Central Administration.


2) In the Application Management tab, under SharePoint Web Application
Management section, click Create or extend Web application link.
3) In Create or Extend Web Application page, click Extend an existing Web
application link. Provide the information to extend the web application and
click OK button. Please see the image below.
Now we have successfully created extranet and internet site. Below is the URL for these
sites.

For extranet site: http://moss2007:36024/sites/fba/default.aspx


For internet site: http://moss2007:36025/sites/fba/default.aspx

Open the browser and test both the site by typing the URL. But these two sites are asking
about windows authentication because these sites are not yet configured to form
authentication.
Below section explains configuration of web.config file of each site with connection string
and providers information.

Configure Web App to communicate with Form Authentication Data Store


In this section, we are modifying the web.config file of two sites. Web.config file resides in
the root directory of the site i.e. c:\Inetpub\wwwroot\wss\Virtual Directories. Under
this, two folders i.e. 36024 and 36025 are available. Web.config file of specific site is
available inside these folders.

Configure web.config file of extranet site

The web.config file of extranet site is available in


c:\Inetpub\wwwroot\wss\VirtualDirectories\36024 folder.

1) Open web.config file, specify the <connectionStrings> node defined in the


section 2.2.c just after the closing </SharePoint> tag and opening <system.web> tag.
Please see the image below:
2) Add the membership and role provider node which is defined in the section 2.2.d, just
after opening the <system.web> tag. Please see the image below
3) Save the web.config file.

Configure web.config file of internet site

The web.config file of internet site is available in


c:\Inetpub\wwwroot\wss\VirtualDirectories\36025 folder.

1) Open the web.config file and follow the same step specified in the Section 4.1
2) Here we need to very careful while specifying defaultProvider information for Role
Provider. In the Role Manager attribute, add AspNetWindowsTokenRoleProvider as
defaultProvider. This is necessary because Central Administration still uses Windows
Authentication for the role provider. Please see the image below:
3) Save the web.config file.

You might also like