Friday, August 20, 2010

Enabling Forms Authentication in Moss (SharePoint)

Steps to get Forms Authentication working with the ASP.NET SQL provider:

(1)   Install the Application Services Database for SQL Server 
     Either of the following two methods can be used:

      (a) Select Start > All Programs > Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio 2008  
           Command Prompt.\
                 enter: aspnet_regsql.exe -E -A all -S localhost\DatabaseServerName

    
(b) You can run the aspnet_regsql utility from c:\windows\microsoft.net\framework\v2.0.50727 to  
create Roles and Membership data on the SQL Server.

          It will create a default database named “aspnetdb”.

(2)  Add the First User
     The database has been created. However, it does not contain any users and therefore we won't be able to  
      log in. We could write a script, or we could access the ASP.NET Web Site Administration Tool to add users

      Option 1: Adding Users by Script
     Simply run the following query in Microsoft SQL Management Studio against the aspnetdb database.

declare @currentTime datetime
set @currentTime = GETDATE()
exec aspnet_Membership_CreateUser 'MossAppName', 'userid','password','','email@domain.com','','',1,@currentTime,@currentTime,0,0,null

Option 2: Adding Users by Creating a Web Application
a. Create a new web application.
b. Add the connection string between the <configuration> tags of the web.config file.

<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=localhost;DATABASE=aspnetdb;TRUSTED_CONNECTION=true;" providerName="System.Data.SqlClient"/>
      </connectionStrings>

             c. From Visual Studio, select Website > ASP.NET Web Configuration.
          d. Click Security > Create User. Add the name of the user as “NewAdmin”

(3)  Modify the moss web.config file
     a. Open the web.config file located in the C:\Inetpub\wwwroot\wss\VirtualDirectories\portnumber folder. 
      b Add the connection string between the <configuration> tags of the web.config file.

<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=localhost;DATABASE=aspnetdb;TRUSTED_CONNECTION=true;" providerName="System.Data.SqlClient"/>
      </connectionStrings>

     Add the Membership and Role Provider details between the <system.web> tag

<membership defaultProvider="AspNetSqlMembershipProvider">
      </membership>
<roleManager enabled="true"   defaultProvider="AspNetSqlRoleProvider">
      </roleManager>

(4)   Modify the Central Admin web.config file 
Add connection and membership provider information to SharePoint Central Administration v3 web.config. We'll need the central administration site to work with forms authentication so that we can add the first administrator of the site. It is important to perform this step, otherwise you won't be able to add the first forms-based administrator later. 

(5)  Configure the SharePoint site for forms authentication
     a. Open SharePoint Central Administration site.
      b. Click Application Management.
      c. In the Application Security section, click Authentication providers. 
      d. Check that you are working with the web application that you wish to configure Forms   
          Authentication for.
      e. Set the the following fields:
      f.       Authentication Mode = Forms 
Membership provider name = AspNetSqlMembershipProvider.
      g. Click Save

(6) Assign the user to be a site collection administrator  
       a.  In SharePoint Central Administration Application Management, click Site Collection Administrators (you  
           can find it in the SharePoint Site Management section).
       b.  Add the user as site collection administrator of the website in which forms authentication will be applied. 

Important Point: One problem that I've faced was mismatch of the Application Name field. It's got to be the same as the one used within the SQL script and in the web.config file.



No comments:

Post a Comment