Monday 25 April 2011

Form Based Authentication in Sharepoint 2007


                 Form based authentication enable us to create users and their profiles in sql server.  This is very useful to provide form to sign up like gmail.   This article explains how to create form base authentication.
                
1.       Open C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
2.       Double click aspnet_regsql.exe


                                  SHAREPOINT is my MS-SQL Server Name



The Database is successfully created in SQL Server
4.  Now we create a UI to create users in this database.  For this we use ASP Dot Net
5.  Open Visual Studio 2008 Create a New web Application
6.  Open Web Config  file add the following code
     Change <authentication mode="Windows" />
      To  <authentication mode="Forms" />
           Change 
           <connectionStrings/>
           To 
            <connectionStrings>
               <add name="fbaSQL"connectionString="server=SHAREPOINT\OFFICESERVERS;
               database=aspnetdb;Trusted_Connection=true" />
            </connectionStrings>

7.Add the following code under <system.web>
<roleManager enabled="true" defaultProvider="fbaRoles">
  <providers>
    <add connectionStringName="fbaSQL" applicationName="/"         name="fbaRoles"type="System.Web.Security.SqlRoleProvider,  
        System.Web,&#xD;&#xA; Version=2.0.3600.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a" />
 </providers>
   </roleManager>
8.       Add this code under  <authentication mode="Forms" />

<membership defaultProvider="fbaMembers">
 <providers>
  <add connectionStringName="fbaSQL" applicationName="/"
    name="fbaMembers"type="System.Web.Security.SqlMembershipProvider,  
    System.Web,&#xD;&#xA;Version=2.0.3600.0, Culture=neutral,   
   PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</membership>
9.       Click Website -> Asp Dot Net Configuration



10.    Select Security Tab

11.   Select Authentication Type

Select From the Internet

                         12.Select Provide Tab
                                 Select a different provider for each feature(advanced)
                           13. Select Fba Members as Membership Provider and Select fbaRoles as Role Provide
                                       then   Click Back
                           14. Click Security Tab and Create User to create a user

                           15 Opent the web config file from C:\Inetpub\wwwroot\wss\VirtualDirectories\
                                    <site name>
                           A. Take a backup for the web config file then open in visual studio Add the 
                                 following code

                           B.   Find the PeoplePickerWildcards replace the following Code
              <PeoplePickerWildcards>
               <clear />
               <add key="AspNetSqlMembershipProvider" value="%" />
              </PeoplePickerWildcards>

                         To
              <PeoplePickerWildcards>
               <clear />
                <add key="AspNetSqlMembershipProvider" value="%" />
                <add key="fbaMembers" value="%" />
              </PeoplePickerWildcards>
 
 
C.  Replace the conncetion String
 
               <connectionStrings>
                <add name="fbaSQL" connectionString="server=spdb;database=aspnetdb;Trusted_Connection=true" />
               </connectionStrings>
 
D.  Add the Code under the <System.Web>
 
                <membership defaultProvider="fbaMembers">
                 <providers>
                  <add connectionStringName="fbaSQL" applicationName="/" name="fbaMembers" 
                   type="System.Web.Security.SqlMembershipProvider, System.Web,
                   Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                 </providers>
               </membership>
 
               <roleManager enabled="true" defaultProvider="fbaRoles">
               <providers>
                <add connectionStringName="fbaSQL" applicationName="/"
                  name="fbaRoles" type="System.Web.Security.SqlRoleProvider, System.Web,
                  Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
               </providers>
              </roleManager>
 
 
                   16.  Opent the web config file from C:\Inetpub\wwwroot\wss\VirtualDirectories\<sitename>
                           Repeat the steeps A -> C
  Add the Code under the <System.Web>
 
             <membership defaultProvider="fbaMembers">
               <providers>
                <add connectionStringName="fbaSQL" applicationName="/" name="fbaMembers" 
                 type="System.Web.Security.SqlMembershipProvider, System.Web,
                 Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
               </providers>
             </membership>
             <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"> 
              <providers>
               <add connectionStringName="fbaSQL" applicationName="/"
                name="fbaRoles" type="System.Web.Security.SqlRoleProvider, System.Web,
                Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
              </providers>
            </roleManager>

                    17.  Rest the IIS
                    18.  Open Central Click Admin Application Management , next select  Authentication
                           Provider Under Application Security
                           Click the  Default in thelist

                          19.  Select Authentication Type as Form Change the Web Application, Type  
                                  Member  Provider Nameas FbaMembers Type Role Manager Name as FbaRoles 
                                  Then Click Save


                           20. Open Central Click Admin Application Management , next select  Policy for  Web 
                                  Authentication  Under Application Security  then Select Add Users

                              21. Click Next
                                    Type User name and click check and give full control

                                  Then click finish
                           23.  Open Web Application in the browser




.