Forms based authentication in SharePoint 2010 - Part 2


Here is Part 1

In this article we will be seeing how to configure forms based authentication for claims based web application using SQL provider.

Creating the database:

  • Open the Visual Studio 2010 Command Prompt.
  • Type aspnet_regsql.
  • ASP.NET SQL Server Setup Wizard will pop up.

    1.gif
     
  • Click on Next.

    2.gif
     
  • Click on Next.

    3.gif
     
  • Click on Next.

    4.gif
     
  • Click on Finish.
  • A database will be created as shown in the following.

    5.gif

Adding users to the SQL database using Web Site Administration Tool:
  • Open Visual Studio 2010.
  • Go to File => New => Web Site.
  • Select the ASP.NET Empty Web Site template.

    6.gif

  • Click Ok.
  • Add the following entry in the web.config file.

              

<configuration>

    <system.web>

      <membership defaultProvider="AspNetSqlMembershipProvider">

        <providers>

          <clear />

          <add name="AspNetSqlMembershipProvider"

       connectionStringName="AspNetSqlProvider"

       applicationName="/"

       type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

        </providers>

      </membership>

      <roleManager enabled="true">

        <providers>

          <clear />

          <add connectionStringName="AspNetSqlProvider" applicationName="/"

            description="Stores and retrieves roles data from the local Microsoft SQL Server database"

            name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

        </providers>

      </roleManager>

    </system.web>

    <connectionStrings>

      <clear/>

      <add name="AspNetSqlProvider"

           connectionString="data source=.; Integrated Security=SSPI;Initial Catalog=aspnetdb;"

           providerName="System.Data.SqlClient" />

    </connectionStrings>

  </configuration>


 
 

  • Go to Website =>ASP.Net Configuration.

    7.gif
     
  • Go to Security => Users => Select authentication type.

    8.gif
     
  • Select "From the internet" option and click done.

    9.gif
     
  • Go to Security => Roles => Enable Roles, enter the role name and click "Add Role".

    10.gif

     
  • Go to Security => Users => Create user.

    11.gif
     
  • Create the new user as shown in the following.

    12.gif
     
  • Once you have created the users you could see the users in the SQL database (Databases => aspnetdb =>Tables =>dbo.aspnet_users).

    13.gif

Create a claim based web application:
  • Go to Central Administration =>Application Management => Manage web applications.
  • In the Contribute group click on New.

    14.gif
     
  • In the Authentication section of the Create New Web Application dialog box, click Claims Based Authentication.

    15.gif
     
  • In the Claims Authentication Types section, select Enable Forms Based Authentication (FBA).
  • Type a membership provider name.
  • Click OK to create the Web application.

    16.gif
     
  • Create a site collection for the web application SharePoint - 2015.

Configure the web.config files:
  • The Central Administration Web application Web.Config file.
  • The forms-based authentication claims-based Web application Web.Config file.
  • The Security Token Service Web.Config file.

Central Administration Web application web.config file:
  • Go to Start => Run => inetmgr.
  • Go to Sites => SharePoint Central Administration => Right Click => Explore.

    17.gif
     
  • Open the web.config file.
  • Inside the <configuration></configuration> section add the following entry.

       <connectionStrings>
            <
    add connectionString="Server=.;Database=aspnetdb;Integrated Security=true" name="AspNetSqlProvider" />
        </connectionStrings>
     
  • And also add the following entry.

      <roleManager defaultProvider="AspNetWindowsTokenRoleProvider" enabled="true">
          <providers>
            <
    clear />
            <
    add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add name="FBARoles" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="AspNetSqlProvider" />
          </providers>
        </
    roleManager>
        <
    membership defaultProvider="FBAMembership">
          <providers>
            <
    clear />
            <
    add name="FBAMembership" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="AspNetSqlProvider" enablePasswordReset="false" enablePasswordRetrieval="false" passwordFormat="Clear" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" />
          </providers>
        </
    membership>
     
  • Save and close the web.config file.

Forms-based authentication claims-based Web application Web.Config file:
  • Go to Start => Run => inetmgr.
  • Go to Sites => SharePoint - 2014 => Right Click => Explore.
  • Open the web.config file.
  • Inside the <configuration></configuration> section add the following entry.

       <connectionStrings>
            <
    add connectionString="Server=.;Database=aspnetdb;Integrated Security=true" name="AspNetSqlProvider" />
        </connectionStrings>
     
  • And also add the following entry.

    <membership defaultProvider="i">
          <providers>
            <
    add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
                    <add name="FBAMembership" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="AspNetSqlProvider" enablePasswordReset="false" enablePasswordRetrieval="false" passwordFormat="Clear" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" />
          </providers>
        </
    membership>
        <
    roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false">
          <providers>
            <
    add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
                    <add name="FBARoles" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="AspNetSqlProvider" />
          </providers>
        </
    roleManager>

Security Token Service web.config file:
  • Go to Start => Run => inetmgr.
  • Go to Sites => SharePoint Web Services =>Security TokenServiceApplication => Right Click => Explore.
  • Open the web.config file.
  • Inside the <configuration></configuration> section add the following entry.

      <connectionStrings>
        <
    add name="AspNetSqlProvider"
             connectionString="data source=.; Integrated Security=SSPI;Initial Catalog=aspnetdb;"
             providerName="System.Data.SqlClient" />
      </connectionStrings>
     
  • And also add the following entry.

      <membership defaultProvider="FBAMembership">
          <providers>
            <
    add name="FBAMembership"
                  connectionStringName="AspNetSqlProvider"
                  applicationName ="/"
                  type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0,  Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          </providers>
        </
    membership>
        <
    roleManager enabled="true"
                      defaultProvider="FBARoles">
          <providers>
            <
    add name="FBARoles"
                  connectionStringName="AspNetSqlProvider"
                  applicationName="/"
                  type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          </providers>
        </
    roleManager>

Policy for Forms-based authentication claims-based Web application:
  • Go to Central administration => Application management => Manage service applications.
  • Select the web application (SharePoint - 2015).
  • In the Policy group, select User policy.

    18.gif
     
  • Click on Next.
  • In the Choose Users section, click on Browse option to search for the users.

    19.gif
     
  • Search for "admin" user who belongs to "Forms auth" category.

    20.gif
     
  • Select the User =>Add => OK.
  • Select the option "Full control - Has full control" from Choose permissions section.

    21.gif
     
  • Click on Ok.
  • Click on Finish.
  • You could see the user added as shown in the following.

    22.gif

Testing:
  • When you try to access the site collection that belongs to the SharePoint - 2015 web application it will be redirected to the login page.
  • Choose forms authentication.

    23.gif
     
  • Enter the user name and password.

    24.gif
     
  • You are now logged into your site as "admin", with site administrator privileges.

    25.gif

 

Up Next
    Ebook Download
    View all
    Learn
    View all