Create a Form Based Authentication Site in Sharepoint2010


Steps For Creating Form Based Authentication

1. Go to the Sharepoint central administration
2. Open application management; in that open "manage web application" under web applications.
3. In ribbon open new web application is present. Click it. Now one window is open called create new web application
4. Check it's in claim based authentication

FrmShr1.gif

5. Enable Form Based Authentication in the same form and give the membership provider name and role manager name.

FrmShr2.gif

6. The last thing I configured was to change the identity of the application pool to Network Service.

FrmShr3.gif

7. Move the cursor and Click ok. It will take a few seconds to complete and at last it will show the window "application created".

FrmShr4.gif

8. Again go to application management and open create site collection under site collections. It will show this page:

FrmShr5.gif

9.In this, in the web application, change the site you created already in web application. Give whatever title you used; for example I used sathya.

FrmShr6.gif

FrmShr7.gif

Then give username and then click ok.

Do step10 or step11. But step11 is best way to do.

10. Open Microsoft SQL Server Management Studio and connect to it. Right-click the database to create a new database.

FrmShr8.gif

FrmShr9.gif


Give database name as aspnetdb and click ok.

11. Open the Visual Studio 2010 Command Prompt from the start menu and type "aspnet_regsql".

FrmShr10.gif

FrmShr11.gif

FrmShr12.gif

FrmShr13.gif

FrmShr14.gif

FrmShr15.gif

12. Open Visual Studio 2010 and create "ASP.NET Empty Web Site"

FrmShr16.gif

Edit the web.config file.

Instead of "<connectionStrings/>" use this code:

  <connectionStrings>
    <clear/>
    <add name="AspNetSqlProvider"
         connectionString="data source=kirke1; Integrated Security=SSPI;Initial Catalog=aspnetdb;"
         providerName="System.Data.SqlClient" />
  </connectionStrings>


In this code give sourcename=your computer name; and then, paste the following code before </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 defaultProvider="AspNetSqlRoleProvider">

      <providers>

        <clear/>

        <add name="AspNetSqlRoleProvider"

              connectionStringName="AspNetSqlProvider"

             applicationName="/"

            description="Stores and retrieves roles data from the local Microsoft SQL Server database"             
            type="System.Web.Security.SqlRoleProvider, System.Web,

            Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

       </providers>

  </roleManager>

13. Run the project and in the Solution Explorer click the ASP.Net configuration symbol.

It shows

FrmShr17.gif

14. Go to security to create a new user and go to role to add roles.
15. To add the connection string

Open the Internet Information Services Manager. Expand the "Sites" node to reveal the web application we created called "SharePoint – sathya".

16. Double-click the Connection Strings feature, and under Actions choose Add. Add a new connection string called AspNetSqlProvider (this is case-sensitive) and click OK.

FrmShr18.gif

The server name is your system name database name that you already created.

17. Now, click on the "SharePoint Central Administration v4" node in IIS Manager.
Double-click on Connection Strings and add a new connection string as you did in the previous step, making sure that you are adding the connection string to the Central Administration application this time.

FrmShr19.gif

18. Expand the "SharePoint Web Services" node in the IIS Manager and choose the "SecurityTokenServiceApplication" node. Double-click on the connection strings feature and add a connection string just like before.

FrmShr20.gif

19. In the IIS Manager, click on the "SharePoint – sathya" node again to reveal the list of features for the web application. Double-click on the "Providers" feature.

Add a new role provider called "FBARoles". Specify the type as "SqlRoleProvider", the ApplicationName as "/", and the connection string name as "AspNetSqlProvider" (available in a drop-down to reduce the likelihood of fat-fingering this).

FrmShr21.gif

Add a new membership provider called "FBAMembership". The type is SqlMembershipProvider, connection string name is "AspNetSqlProvider", and the application name is "/".

FrmShr22.gif

20. Do the previous step for both central administration and Sharepoint web services. Keep in mind while proceeding with changes in Sharepoint web services, don't make changes directly, for this refer to the following screen shot

FrmShr23.gif

21. Edit Web.Config for Central Administration

In the previous section, we added a configuration for a connection string, membership, and roles to our web application. We also need to add these settings for Central Administration so that we can add our forms-based authentication users as site collection owners (among other settings).

We need to make a few small tweaks to the configuration for Central Administration because there isn't a way (that I could find, anyway) to do this using the MMC console:

  1. The defaultProvider for the role section must be AspNetWindowsTokenRoleProvider.
  2. The defaultProvider for the membership section must be our new membership provider, "FBAMembership".

For this right-click the central administration in IIS and click explore.

<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"
          enablewordReset="false"
          enablewordRetrieval="false"
          wordFormat="Clear"
          requiresQuestionAndAnswer="false"
          requiresUniqueEmail="false" />
  </providers>
</membership>

While we are editing the web.config for Central Administration, there's one more thing that we need to be sure to add. We need to enable wildcard searches for our users when using the People Picker control. This section is located under configuration/SharePoint/PeoplePickerWildcards.

    <PeoplePickerWildcards>
      <clear />
      <add key="FBAMembership"
           value="%" />
    </PeoplePickerWildcards>

22. Edit Web.Config for the Secure Token Service Application

Just like we did with Central Administration, we need to set the default providers for the Secure Token Service Application. Open the web.config file at:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\SecurityToken\web.config

You will need to add your connectionStrings section and a web.config section. A partial listing showing the configuration that needs to be added is:

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

23. Add the user in the site that is present in manage web application under application management in central administration.

For this click that site and go to user policy that is present in the ribbon. It shows one window; in that click "add users". It shows the Add users window; in that select "default" and give "next" and select user from people picker.

Select user that you already gave in create users in Visual Studio. Give permission and click ok.

Up Next
    Ebook Download
    View all
    Learn
    View all