Search This Blog

Sunday, November 30, 2014

SharePoint Managed Paths

SharePoint Managed Paths

“A managed path is a location within a web application in which you can have site collections.”

 1.    Managed paths are used to define the location of every site collection inside of SharePoint.
2.    Managed paths follow the same concept as a virtual directory in IIS however they are handled directly by SharePoint.
3.    A managed path defines a sub-directory in your application which you can use as a url for a site collection.
4.    By default SharePoint 2010 creates 2 managed paths when you make a new web application and sites. 
5.   

The dialogue below allows you to create managed paths and can be found in the ribbon menu for web applications in central admin.


There are 2 types of managed paths you can create:

Explicit Paths
These are used if you want to place a site collection directly at the sub-directory you specify. For example if you want a site collection at http://site/bob you would use an explicit path.

However explicit paths may only contain a single site collection.

Wildcard Paths
A wildcard path is used if you want to have multiple site collections under a path. For example http://site/projects/project1 andhttp://site/projects/project2.

Wildcard paths can only have site collections below the path (ie no site collection at http://site/projects)
Few Key points
1.   Managed Paths allow SharePoint to determine what portion of a given URL corresponds to the "site collection URL".
2.   Managed Paths can be defined per web application (and cannot be defined for host headersite collections)
3.   Managed Paths can be "Explicit" or "Wildcard"
4.   Explicit Managed Paths allow a single spsite to be created at exactly the given url
5.   Wildcard Manage Paths allow unlimited spsites to be created under the given url – no spsite can be created at exactly that URL.
6.   Limit your managed paths to <20 per web application 

What is a managed path in SharePoint?

Answer

“A managed path is a location within a web application in which you can have site collections.”

There are two types of managed paths:
1.     An explicit inclusion managed path defines an exact path to which a site collection can be directly attached.
2.     A wildcard inclusion managed path defines a path that cannot have a site collection attached at its root but can have multiple site collections assigned beneath it.

Question

Why use a managed path in SharePoint?

Answer

“You would use a managed path in SharePoint to categorize, organize or group together site collections.”

First, if you are an organization with only one site collection, you can pretty much skip this entire post. Although even if you have only one site collection you are still ‘technically’ using a Managed Path, understanding managed paths in SharePoint 2010 are useful for farms that will have at least a few or many site collections and want to keep them in some type of structured or organized placement.
SharePoint uses the managed path to determine which content database the URL a user entered is in. Every URL request that comes into your server actually looks at the URL structure, looks up the managed paths listed in Central Admin, then routes the request to the proper database to retrieve the content. Knowing this, the more managed paths you add, the slower the performance so try to keep the number at a minimum (>20).
Another reason to use managed paths is to keep structure and organization in where you place your site collections. For example, if your IT department has several divisions, and each division wants their own site collection for security and “power hungry control freakish” reasons, you would want to make a managed path called IT. You can then create a site collection under this for each division, such as:
http://ourIntranet.com/IT/Infrastructure
http://ourIntranet.com/IT/SharePointTeam
http://ourIntranet.com/IT/OracleTeam
This organizes the site collections for each IT division into a sensible manner.
Understanding Managed Paths in SharePoint 2010 isn’t so easy at first look, hopefully this gives you a clearer understanding of their purpose and if your organization will have the need to utilize them. True that.

 Understanding Sharepoint Managed Paths


When we create Site Collections in Sharepoint web applications, they are created with URL as 

http://servername:port/site/

To have a specific URL other than /site we would have to create a Managed Path.

When we create a Managed Path, we have two options:   Explicit Inclusion
                                                                                    Wildcard Inclusion

So what is the difference? I am going to guide you on what exactly is a managed path. Be with me. 

1) Browse to Central Administration -> Applications Management -> Manage Web Application

2) Choose the web application where you want to implement managed paths.

3) Select Managed Paths from the ribbon



4) I am adding two new paths      - fahadexplicit (for type Explicit inclusion)
                                                 - fahadwildcard (for type Wildcard inclusion)


5) Now browse back to Application Management -> Create Site Collections.

6) You would see your custom Managed paths there.

Explicit Inclusion:

When we are not planning to create further site collections under a specified managed path, then we use this option. Explicit Inclusion Managed paths allows in creation of only one site collection at the exact given URL.
In our case fahadexplicit would be the only site collection that can be created. SharePoint will allow creating only one site collection within this Managed Path.

The URL would be: http://servername:port/fahadexplicit



Wildcard Inclusion:

When we want to create more than one site collection under a specific managed path, we use this option. Wildcard Inclusion Managed Paths allow unlimited site collection to be created under a given URL.
In our case under fahadwildcard, we can create any number of site collections.

The URL of these site collections would be as below:

http://servername:port/fahadwildcard/sitecolelction1
http://servername:port/fahadwildcard/sitecolelction2
http://servername:port/fahadwildcard/sitecolelction3
http://servername:port/fahadwildcard/sitecolelction4



and so on.

Programmatically create Managed Paths in SharePoint 2010

Introduction:
Managed Paths - We can specify which paths in the URL namespace of a Web application are used for site collections. We can also specify that one or more site collections exists at a specified path.
 
Types of Managed Paths:
  • Explicit inclusion.
  • Wildcard inclusion.
Explicit inclusion:
An explicitly named path is used for a single site collection.

Example: http://server/sites/team.

Wildcard inclusion:
A wildcard path of "sites" indicates that child URLs of the path are site collections. An wildcard named path is used for a multiple site collections.

Example: http://server/sites/

In this article we will be seeing the following
  • Programmatically create managed paths
  • Programmatically get all the managed paths for a web application
Programmatically create managed paths:
  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select the console application template.
  • Add the following references.
    • Microsoft.SharePoint
  • Add the following namespaces.
    • using Microsoft.SharePoint;
    • using Microsoft.SharePoint.Administration;
  • Replace Program.cs with the following code.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.SharePoint;using Microsoft.SharePoint.Administration; namespace ManagedPath
{
    class Program    {
        static void Main(string[] args)
        {
            string path = "Bangalore";
            SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://serverName:1111/"));
            SPPrefixCollection prefixColl = webApp.Prefixes;
            if (prefixColl.Contains(path) == false)
            {
                SPPrefix newPrefix = webApp.Prefixes.Add(path, SPPrefixType.ExplicitInclusion);
                Console.WriteLine(path+" is successfully added to the web application");
            }
            else            {
                Console.WriteLine(path + " already existe in the web application");
            }
            Console.ReadLine();
        }
    }
}
  • Build the solution.
  • Hit F5.
Output:
  • Go to Central Administration => Application Management => Manage Web Applications.
  • Select the web application, click on Managed Paths available in the ribbon interface.

    Untitled-2.gif
  • "Bangalore" managed path is created successfully.
Programmatically get all the managed paths for a web application:
Code:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.SharePoint;using Microsoft.SharePoint.Administration; namespace ManagedPath
{
    class Program    {
        static void Main(string[] args)
        {
            SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://serverName:1111/"));
            SPPrefixCollection prefixColl = webApp.Prefixes;
            foreach (SPPrefix prefix in prefixColl)
            {
                Console.WriteLine("Managed Path :{0}, Prefix Type :{1}", prefix.Name, prefix.PrefixType);
            }
            Console.ReadLine();
        }
    }
}

Output:

Untitled-3.gif

To create, get and delete the managed paths for a web application using PowerShell refer 

http://www.c-sharpcorner.com/uploadfile/anavijai/5355/.
 





No comments:

Post a Comment