Search This Blog

Wednesday, July 17, 2013

Define Managed Path in SharePoint

A Managed path is a location within a web application to use for site collections,You can specify that one or more site collections exist at a specified path.

As an example, sites is the managed path in http://<site>/sites/madison. Managed paths cannot be limited for use by specific security groups, nor can they be targeted directly with audiences. They are simply a way to organize a large quantity of site collections.

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:

To add a managed path by using Central Administration

Verify that the user account that is performing this task is a member of the Farm Administrators SharePoint group.

1. On the the SharePoint Central Administration website, click Application Management.
2. On the Application Management page, click Manage web applications.
3. Click the web application for which you want to manage paths.

 4. The ribbon becomes active.In the Manage group of the ribbon, click Managed Paths.
On the Define Managed Paths page, in the Add a New Path section, type the path to include.
Click Check URL to confirm the path name.


In the Type list, select either Wildcard inclusion or Explicit inclusion to identify the type of path.


Wildcard Inclusion:

The Wildcard inclusion type includes all paths that are subordinate to the specified path.

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 HR , we can create any number of site collections.

The URL of these site collections would be as below:

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


Explicit Inclusion:

The Explicit inclusion type includes only the site that is indicated by the specified path. Sites subordinate to the specified path are not included.



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 HRwould 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/HR



5. Click Add Path.
6. When you have finished adding paths, click OK.


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 header site collections)
3. Managed Paths can be "Explicit" or "Wildcard"
Explicit Managed Paths allow a single spsite to be created at exactly the given url
Wildcard Manage Paths allow unlimited spsites to be created under the given url – no spsite can be created at exactly that URL.
4. Limit your managed paths to <20 per web application


To  create either explicit or wildcard managed path programmatically.

 Following code snippets shows two different ways to create managed paths. Both ways shows different ways to access the SPWebApplication application object – using URI or SPSite to create managed path.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace CodeSnippets
{
class Program
{
static void Main(string[] args)
{
//Retrieve the Input Arguments
string url = string.Empty;
if (args.Length > 0)
{
Console.WriteLine("Input Web App URL: " + args[0].ToString());
url = args[0].ToString();
}
else
{
url = "<a href="http://sp2013proj:4545/">http://sp2013proj:4545</a>";
}

//Create Managed Path
CreateManagedPathUsingWebAppURI(url, "HR", true);
CreateManagedPathUsingWebAppURI(url, "IT", false);
CreateManagedPathUsingSPSite(url, "ADMIN", true);
CreateManagedPathUsingSPSite(url, "SALES", false);
}

////Method 1 - Create Web App object using URI
private static void CreateManagedPathUsingWebAppURI(string webAppURL, string NewSiteCollectionName, bool isWildCardInclusion)
{
SPWebApplication spWebApp = SPWebApplication.Lookup(new Uri(webAppURL));
SPPrefixCollection prefixColl = spWebApp.Prefixes;
if (prefixColl.Contains(NewSiteCollectionName) == false)
{
if (isWildCardInclusion)
{
SPPrefix prefix = spWebApp.Prefixes.Add(NewSiteCollectionName, SPPrefixType.WildcardInclusion);
}
else
{
SPPrefix prefix = spWebApp.Prefixes.Add(NewSiteCollectionName, SPPrefixType.ExplicitInclusion);
}
}
}

//Method 2 - Reference Web App Object from SPSite
private static void CreateManagedPathUsingSPSite(string webAppURL, string NewSiteCollectionName, bool isWildCardInclusion)
{
using (SPSite spSite = new SPSite(webAppURL))
{
SPWebApplication spWebApp = spSite.WebApplication;
SPPrefixCollection prefixColl = spWebApp.Prefixes;
if (prefixColl.Contains(NewSiteCollectionName) == false)
{
if (isWildCardInclusion)
{
SPPrefix prefix = spWebApp.Prefixes.Add(NewSiteCollectionName, SPPrefixType.WildcardInclusion);
}
else
{
SPPrefix prefix = spWebApp.Prefixes.Add(NewSiteCollectionName, SPPrefixType.ExplicitInclusion);
}
spWebApp.Update(true);
}
}
}
}
}


Enjoy! :).......

No comments:

Post a Comment