Tuesday, March 27, 2012

Create Form Based Authentication-FBA(SQL Membership)

To create form based authentication,we have to create the site as claim based authentication.
First create that site with windows authentication.
Step1:Create a db for membership user, roles and etc., by execute this exe “C:\Windows\Microsoft.NET\Framework\v2.0.50727”-asnet_regsql
Step2:We have to do changes in 3 web.config files
   1.site’s web.config
  2.central admin’s web.config
 3.webservice’s  web.config (we can find this from iis we can find “sharepoint web services”site , by exploring that site can get we.config of the webservice site).
Replace membership and rolemanager tag with following code

    <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>

Step3:Add connection string to that 3 web.config files
By adding the following codeLChange connection string to your DB.
<connectionStrings>
    <add connectionString="Data Source=SP4\SQLEXPRESS;Initial Catalog=fbaDB;Integrated Security=True" name="AspNetSqlProvider" />
  </connectionStrings>

Step4: Make sure that , defaultProvider is AspNetWindowsTokenRoleProvider and enabled true

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


Step5:change that site to FBA
In central admin –manage web application-select that site and choose-Authentication Provider

It ll give you a popup

Select and change the default authentication provider

Step6:ASP.NET Memership provider name: FBAMembership and ASP.NET Role Provider Name:FBARoles
And save that.
Step7: create some users in that membershipDB
          1.Create a webapplication(asp.net site in VS2010)
          2.configure membership DB for that
         Ie) add connectiostring for your membershipDB
In <connectionstrings> tag paste this code
<add name="ApplicationServices" connectionString="data source=sp4\SQLEXPRESS;Initial Catalog=fbaDB; Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
  

And configure membership database  again  ,create users(Don’t enable roles for this site)
Step8: change site collection administrator to your Membership user(created in step7)

Step9: Login by Using Form Based Authentication

No comments:

Post a Comment

Creating Provider hosted app (sharepoint online) with local hosted IIS

The Pre-requires are as follows. 1. Office 365 Subscription 2. Visual Studio 2015 (Professional/Community/Enterprise Edition) With t...