Saturday, September 10, 2016

Configure FBA in SharePoint 2013

Configuring FBA in SharePoint 2013
--------------------------------------------------

1.  Run the  Aspnet_regsql. exe  from the following path for framwork 4.0

       Path:  %windir%\Microsoft.NET\Framework64\v4.0.30319

2. Default Database Will be created as aspnetdb

3. create a user in security/logins and give right to user as FBA_USER_ACCOUNT or any name.

4. After that you need to place membership and role provider to 3 Web config files.

   1. Central admin
   2. Web application
   3. STS service app
5. Open Central admin config file and place the below markup at specific place.

Find this:
--------------

<sessionState mode="InProc" timeout="20" cookieless="UseCookies" />

//******************************************* These markup ***********************************************************
    <membership>
      <providers>
          <add name="FBA_MEMBERSHIP" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="FBA_CON" enablePasswordReset="true" enablePasswordRetrieval="false" passwordFormat="Clear" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" />
      </providers>
    </membership>
    <roleManager>
      <providers>
          <add name="ROLE_PROVIDER" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="FBA_CON" />
      </providers>
    </roleManager>

//**********************************************End Markup ****************************************************************
  </system.web>
  <system.webServer>

Now Find in the end:  </configuration> 
------------ 
//******************************************************************************************

 <connectionStrings>
        <add connectionString="Server=CLIENTVM01;Database=aspnetdb ;Uid=FBA_USER_ACCOUNT; Pwd=user@123" name="FBA_CON" />
    </connectionStrings>
//****************************************************************************************
</configuration>

6. Now Open the Web Application config file

Find: <machineKey validationKey and place this below this tag

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

//************************************************************************************************************************
  </system.web>
  <system.webServer>

7. Now open the STS config file:
    Find: </system.net>

Place this markup below this
//************************************************************************************************************************
<connectionStrings>
    <add connectionString="Server=CLIENTVM01;Database=aspnetdb ;Uid=FBA_USER_ACCOUNT; Pwd=user@123" name="FBA_CON" />
  </connectionStrings>
  <system.web>
    <roleManager>
      <providers>
        <add name="ROLE_PROVIDER" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="FBA_CON" />
      </providers>
    </roleManager>
    <membership>
      <providers>
        <add name="FBA_MEMBERSHIP" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" connectionStringName="FBA_CON" enablePasswordReset="true" enablePasswordRetrieval="false" passwordFormat="Clear" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" />
      </providers>
    </membership>
</system.web>

//*************************************************************************************************************************** 
</configuration>

8: Now Create users in IIS, Making Membership and Role manger as default which you created now.

9. After creating the users make Membership (i) and Role manager (c) as default, OOBs

10. add FBA users to site and login.





Saturday, September 3, 2016

How to write a log in txt File

How to write a log in txt File

Using System.Diagnostic;

 public void WriteLogg(string errorDescription)
        {
            System.IO.StreamWriter objWriteLog = System.IO.File.AppendText("C:\\temp" + "\\log.txt");
            try
            {
                FileInfo fileInfo = new FileInfo("C:\\temp\\log.txt");
                if (!fileInfo.Exists)
                {
                    File.Create("C:\\temp\\log.txt");
                }
                objWriteLog.WriteLine("Date and Time : " + DateTime.Now.ToString());
                objWriteLog.WriteLine("errorDescription : " + errorDescription);

            }
            catch (Exception ex)
            {
                EventLog eventLog = new EventLog();
                eventLog.Source = "DocEvent";
                eventLog.WriteEntry(errorDescription + "- er: " + ex, EventLogEntryType.Warning);
            }
            finally
            {
                objWriteLog.Close();
            }
        }