Search This Blog

Wednesday, February 3, 2016

Configure Forms Based Authentication in SharePoint 2013

Description:

Today we are going to see how to Configure Forms Based Authentication in SharePoint 2013. In SharePoint, Microsoft offering two different types of authentication such as Windows Authentication and Forms Based Authentication. By default we will get the windows authentication to our site but if we want to provide the Forms based authentication to our SharePoint site we must have to do some settings while creating of web application of a site. Now we will see step by step process of configuring forms based authentication in SharePoint 2013.
What is Windows Authentication in SharePoint?
Windows authentication is a secure form of authentication which is offered by Microsoft and the user name and password are hashed before being sent across the network. When you enable the Windows authentication in our SharePoint Site, the client browser sends a strongly hashed version of the password in a cryptographic exchange with our Web Server. We will get the users information such as username, password, role, and group he/she belongs, from the Active Directory and store the user information into content database of SharePoint, this will happens in installation process of SharePoint Farm or we can do it after installation of SharePoint using user management services in SharePoint.
What is Form Authentication in SharePoint?
Some companies maintain their employ user information in databases rather than Active Directory. So here all the users information such as usernames, passwords, roles and groups will stored in a database that may be MS SQL, Oracle or MySQL in this type of situations most of the companies will prefer to use form based authentication instead of rebuild the new Active Directory.

Steps to work with FBA 
1  1. Create Database
    2. Create Web Application
    3.  Modify 3 web. Configuration files
i.             FBA  (web Application) 
ii.           Central Administration
iii.          STS (Security service Token)
    4.Set user policy

Step-1: Create Database

Create Database using aspnet_regsql.exe Application
Go to the location C:\Windows\Microsoft.NET\Framework64\v4.0.30319

And select aspnet_regsql.exe  right click select run as administrator



 It opens
  è ASP.Net SQL server Setup wizard
  è Click on next button
  è Select the SQL server for application services and click on next button
  è Select the server and data base details
     Server: SQL Server Name (System name) (ex: HYD38)
     Select authentication type windows
     Database Name: FBADB
  è Click on next button and next and finish.
Note: Check the database name FBADB and its table’s names (like users, roles  ...Etc.)  In SQL Server

Step step2: Create Web Application

  è Go to central administration
  è Click on Application management
  è Click on new
  è Give following details 




Click on OK.

Web application creates and it asks you want create site collection
Click on Create Site Collection page. 

Create Site collection:
Give site title, template name and primary site collection administrator name
Click on OK button

Step3: Modify 3 web. Configuration files
i.             FBADemo Web Application web.config file (Add connection string, Membership provider and role provider)

Go to IIS
Go to run command (Window+R)
  è Enter inetmgr
  è Press enter button it open IIS
  è Go to sites
Click on web application (FBADemo – 6666)

a.   Connection string

In middle pan double click on Connection Strings icon
On the right pan click on Add and the enter the details bellow



Click on OK button.
b.    Member ship provider

Click on web application (FBADemo – 6666)
In middle pan double click on Providers icon
In middle pan select feature type .Net User


On the right pan click on Add and the enter the bellow details 


Click on Ok button

c.    Role provider :

Click on web application (FBADemo – 6666)
In middle pan select feature type .Net Roles


On the right pan click on Add and the enter the bellow details 


Click on Ok button

d.   Create role
Click on web application (FBADemo – 6666)
In middle pan double click on .net Roles icon and it displays following error message



We need to change default role provider to FBARoleProvider

So click on right pan set Default provider
And change default provider ‘c’ to FBARoleProvider 




Click on OK

Click on add right pane and give role name r1


Click on OK
Similarly create other roles like r2, r3, etc.

e.   Create User
Click on web application (FBADemo – 6666)
In middle pan double click on .net Users icon and it displays following error message


We need to change default member ship provider to FBAMembershipProvider

So click on right pan set Default provider
And change default provider ‘i’ to FBAMembershipProvider
Click on OK
Click on add right pane and give the details 


Click on next
Select role type r1 and click on finish.
Similarly create other users like user_02, user_03 etc.

Note: revert to default membership provider FBAMembershipProvider to ‘i’            and default role provider FBARoleProvider to ‘c’
   If you got any error message just click on OK.

i.             Click on web applications (SharePoint Central Administration v4)
Repeat the steps in above web application (FBADemo – 6666)
a, b, c ( Connection string , member ship provider  and role provider) details

ii.            Click on web applications (SharePoint Web Services)
        Repeat the steps in above web application (FBADemo – 6666)
             a, b, c ( Connection string , member ship provider  and role                     provider) details

Note: In central admin we need to change default Membership provider
ASPNetSQLMembershipProvider  to FBAMembershipProvider 


             Similarly Change
            Default Role provider
            ASPNetSQLRoleProvider to   ASPNetWindowsTokenRoleProvider
1.   Set user policy

Go to center Admin select the FBADemo Web Application
Click on user policy on the top of the ribbon
Next click on Add users
Next select “All zones”
Next select the User: user_01 or All Users (FBAMembershipProvider)All Users (FBAMembershipProvider)
And Permission: full control
Click On finish.
Note: Uncheck the anonymous access to the web application. If you are not added user to user policy you got following message
Sorry, this site hasn't been shared with you. 
So in user selection you can select All Users (FBAMembershipProvider)All Users (FBAMembershipProvider)instead of user_01

Note: if the site users have different permission levels so you can create separate groups for users i.e. Viewers, Members and Owners. Add these users to respective groups while creating the users at registration page.

Apply FBA permission to List
Go to list
Click on list settings
Next click on permissions for this list
Next Click on stop inheriting permission
It display one popup like create unique permissions for this?
Click on OK
Next click on grant permissions on the top of the ribbon
Enter All Users (FBAMembershipProvider)


Tuesday, February 2, 2016

How to Create and Host WCF Service Inside SharePoint 2013

Windows Communication Foundation:
Windows Communication Foundation (WCF) takes many existing communication technologies, such as Web Services, Windows Remoting, Microsoft Message Queuing, and abstracts them into a single technology. In most cases, this simplifies the way you communicate with other applications. It also allows you to communicate with other applications without being coupled to a specific technology. In this we are going to create a simple WCF service and we are going to host that service inside a SharePoint site (in the _vti_bin folder) .
Procedure to create a WCF Service
The following procedure should be followed to create a WCF service using Visual Studio 2010.
  1. Open Visual Studio 2010.
  2. Go to File => New => Project.

    1.gif
  3. Select Empty SharePoint Project under installed template category SharePoint and name it WCF.
  4. Target the .Net Framework 3.5.
  5. Click OK.
  6. In the SharePoint Customization Wizard, enter the URL of the local site where you want to use (http://demo2010a:5000/) and select "Deploy as a farm solution".
  7. Right-click the Solution Explorer, click Add and select the SharePoint Mapped Folder.

    2.gif
  8. In Add SharePoint Mapped Folder select ISAPI.

    3.gif
  9. Right-click on ISAPI and Add a New Folder.

    4.gif
  10. Name the folder WCF.
  11. Right-click on WCF and Add a New item.
  12. Select a text file from the installed templates and name it Service.svc.

    5.gif
  13. Add another text file and name it web.config.

    6.gif
  14. Right-click on the ISAPI and Add a new item.
  15. Select a Class file from the installed templates and name it Service.cs.

    7.gif
  16. Again add a new item, select Interface file and name it IService.cs.

    8.gif
  17. The solution in the Solution Explorer should look like the following:

    9.gif
  18. Add a reference to the Microsoft.SharePoint.Client.ServerRuntime assembly. This assembly contains the Service Host Factory classes, as well as some attributes we need later on.
IService.cs:
using System;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.Text;namespace WCF.ISAPI{    [ServiceContract]    publicinterfaceIService    {        [OperationContract]        stringgetTime();    }}
Service.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
namespace WCF.ISAPI
{
    [ServiceBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode =AspNetCompatibilityRequirementsMode.Allowed)]
     public class Service : IService    {
         public string getTime()
       {
              returnDateTime.Now.ToString();
       }
    }  
}

Service.svc:
To get Version, PublicKeyToken, and Assembly type name use the SN.EXE utitlity. 

<%@ServiceHostDebug="true"Language="C#"CodeBehind="Service.cs"Service="WCF.ISAPI.Service,WCF, PublicKeyToken=1b762f52dfc6b6d8,Version=1.0.0.0, Culture=Neutral"%>

web.config:
<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="WCF.ISAPI.ServiceBehaviour"
        name="WCF.ISAPI.Service">
        <endpoint address=""
                  binding="basicHttpBinding"
                  contract="WCF.ISAPI.Service" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding"contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://demo2010a:5000/"></add>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name=" WCF.ISAPI.ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid
disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Checking anonymous authentication to the SharePoint site:

  1. Go to Run and type inetmgr.

    10.gif
  2. Expand sites and click on SharePoint- 5000 (SharePoint Site where we are going to deploy the WCF service).

    11.gif
  3. Click Authentication as shown in the above figure.

    12.gif
  4. Check whether the status of Anonymous Authentication is enabled.
Testing the Service:
  1. Deploy the Project.
  2. Go to the URL http://demo2010a:5000/_vti_bin/WCF/Service.svc.

    13.gif
  3. We have successfully created a WCF service and hosted it inside a SharePoint (_vti_bin folder).

SharePoint Experience Expertise Content

Which is better - SPS or STS?

Before we begin - let us see what do these two abbreviations stand for.

1. SPS means SharePoint Portal Services
2. STS means SharePoint Team Services

- Document management system in SPS is better than STS.
- The search engine in SPS is better, more efficient and possesses the capability to crawl multiple content sources in comparison to STS.
- If Document Management is not required, STS is easier to manage for team environment while SPS is better for an organization where Document Management is required.

Differentiate between CustomMasterUrl & MasterUrl?

MasterUrl is used to change the layout of all end user pages while CustomMasterUrlis used for changing the layout of admin pages.

Explain Farm in SharePoint.

- Farm is a collection of SharePoint servers with same configuration database.
- All the required information to run the farm is carried in Configuration DB. There exists only one configuration database for each farm.
- Central administration is used for the administration of each farm.

Explain WebApplication.

- WebApplication is a IIS website. Content database is created for each WebApplication.
- WebApplication can be created from central admin.
- Once a web application is created, it can be extended to different zones.

What tools can be used to back up a SharePoint 2010 environment?

- SharePoint farm backup and recovery
- SQL Server

What do you mean by Field Control?

- Field controls are ASP.NET 2.0 server controls. They provide basic field functionality in SharePoint.
- They also provide basic general functionality such as displaying or editing list data as it appears on SharePoint list pages

Explain an ancestral type. How is it related to content types?

- An ancestral type is the base type that the content typed is derived from.
- It defines the metadata fields included with the custom content type.

Explain Module in Sharepoint

- A module is a file or collection of file instances which define the location where the files are installed during site creation.
- They are used to implement a Web Part Page in the site.
- Modules can be defined by using a module element within a feature definition file.

Explain the CreateChildControls() method with an example

CreateChildControls() method notifies the server about the control that to implement the child controls for posting back and for rendering. The statement is given as:
Protected: virtual void CreateChildControls();

The example shows the implementation of the CreateChildControls() method that is:
‘Override CreateChildControls to create the control tree.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub CreateChildControls()

' Add a LiteralControl to the current ControlCollection.
Me.Controls.Add(New LiteralControl("<h3>Value: "))


' Create a text box control, set the default Text property,
' and add it to the ControlCollection.
Dim box As New TextBox()
box.Text = "0"
Me.Controls.Add(box)

Me.Controls.Add(New LiteralControl("</h3>"))
End Sub 'CreateChildControls

This is the method that is used to instantiate the control and fetches the properties to set it according to the website. The add () method of the control class adds the control in the collection. The method CreateChildControls () implies that the WebPart consists of a collection of child controls.

What are the different types of elements used in CAML?

CAML allows the developers to construct and display the data using the rendering process and other processes. CAML consists of different types of elements to represent the lists and the sites by using some predefined style.

1. Data definition elements : It is used to define the lists and the sites by using the XML tags with the same style. The code will look like this:
<Fields>
<Field Type="Counter" Name="ID"/>
// insert other statements here
</Fields>

2. Data rendering elements : CAML also allows the generation of HTML based sets that use the tags like the loops that are used to loop around a given condition. The example is given below that shows the drop down menu with choices:
<ForEach Select="CHOICES/CHOICE">
<HTML>fld.AddChoice(</HTML>
<ScriptQuote>
<Property Select="."/>
</ScriptQuote>
<HTML>, </HTML>
<HTML>);</HTML>
</ForEach>


What is the difference between the Sharepoint Web-Part and ASP.NET 2.0 Web-Part base class?

The difference between the two types lies in the architecture produced by them:

Sharepoint webpart base class : Is designed to build over the Microsoft ASP.NET web part infrastructure. Whereas, ASP.NET 2.0 WebParts base class : Provide the integrated set of controls to create a website. This enable the user to modify the content and behavior of the webpage using the user interface and directly from the browser.

Sharepoint webpart base class : It provides the backward compatibility and can be used with ASP.NET application also and other applications that include the functionality to execute the code. Whereas,ASP.NET 2.0 WebParts base class : Doesn't include backward compatibility and allow easy to use user interface.

Sharepoint webpart base class : There are some features to be provided with it such as:

1. Cross page connections : This is used to include the pages that are connected with each other but not as a part of the website.
2. Connections between Web Parts : These are the connections that are outside the Web Part.
3. Client-side connections : Includes the webpart service components that include all the services that are required to be shown.
4. Data caching infrastructure : Consists of the data structure that is used to keep all the data in the cache for future use.
Whereas, ASP.NET webparts base class : Consists of controls that can be saved and some session that can be personalized using the web part capabilities.

ONET.xml -

1) Onet.xml file specifies all the components contained in a site. It is considered as the core of a site definition.
2) It is present at following location: 
%SharePoint Root% \TEMPLATE\SiteTemplates\XML\Onet.xml



Thursday, January 21, 2016

Retrieve items from a particular folder of a list or Library SP 2013

Lists and Libraries are the commonly used data storage components is a SharePoint portal. With data growing huge in the lists, site administrators usually create folders to make the data organized. We use the 'ViewAttribute' of the SPQuery object to fetch all the items from the folders and sub folders. Below is a sample code snippet
using (SPWeb spWeb = SPContext.Current.Site.AllWebs["Reports"]) { SPList spList = spWeb.Lists.TryGetList("ManageReports"); SPQuery spQuery = new SPQuery(); //Setting the ViewAttribute to "Scope='Recursive'" //fetches all items from the list, //ie., also the items within the folders spQuery.ViewAttributes = "Scope=\"Recursive\""; SPListItemCollection items = spList.GetItems(spQuery); }
If the 'ViewAttribute' is not specified for the SPQuery object, then only those items which are in the root folder (ie., the root level of the list) are returned. So, we need to specify the scope in ViewAttribute property to get the items from all the folders (if any) of a list.
GETTING ITEMS FROM A SPECIFIC FOLDER
In some scenarios we might need to fetch only the items within a sepcific folder. For this we can use the 'Folder' property of SPQuery class. Prepare the SPQuery object with the required CAML query, set the RowLimit and other required settings. And then set the 'Folder' property to a Folder object which represents the folder instance from where we need the items. Refer the below code snippet
using (SPWeb spWeb = SPContext.Current.Site.AllWebs["Reports"]) { SPList spList = spWeb.Lists.TryGetList("ManageReports"); SPQuery spQuery = new SPQuery(); //Getting the folder object from the list SPFolder folder = spList.RootFolder.SubFolders["FolderName"]; //Set the Folder property spQuery.Folder = folder; SPListItemCollection items = spList.GetItems(spQuery); //Now the items collection will have the items only from the given Folder }

Tuesday, January 12, 2016

Add “Link to a Document” to a Document Library

I threw this together for a customer, and figured I’d blog it, as it’s generally fairly useful to remember how to do this again in the future.  The steps below help to guide you through the process of adding the “Link to a Document” content type to a document library.
1) Go into the Site Actions -> View All Site Content, and find the library you want to change
image
2) Go into the Library Settings for that library
image
3) Go into “Advanced Settings”, and choose “Allow management of content type” – Select “Yes”, when done, click “OK”
image
4) A new option will now be available on the Library Settings page, “Content Types”.  Choose “Add from existing site content types”.
clip_image002[5]
5) From the list on the left, find “Link to a Document” and add it to the list on the right.
image
6) You will now have 2 content types, including “Link to a Document”.  Exit the settings page.
clip_image012
7) In your library, you will now have the ability to add a link to a document as a library “item”.  Choose this, and let’s try it out.
image
8) Basically what this allows you to do is to create a name / value pair, where the “Document Name” is what will show up in the library as the “name” and the URL is basically any reference that you want it to be (it could even link to google.com – for all SharePoint cares).  What you’ll likely want this to be is a URL to a document in the other site’s document library.
clip_image016
9) Finally, in case you didn’t know, the easiest way to get the Document URL for a file is to go to the file and choose “Email a link”.  This will pop open a new email message, but it’s the easiest means of getting the URL to a document.  Just steal the URL from the email and throw the email away.  Finally, paste that value into the dialog above, and you’re all set!
image
image
That should get you everything you need.