SharePoint Connections – Sessions Follow Up
November 14, 2006
RTW of WSS and Office SharePoint Server Standard and Enterprise Evaluation Can Now Be Downloaded
November 17, 2006

HOW TO: Prevent creation of sub sites within MOSS 2007 My Sites

What do you do to prevent your users from creating sub sites under their My Sites if you need to do so? Since there is not a way to shut down this ability from the Central Administration site you’ll need to use some custom code to get the job done. The cool part is, I already wrote it for you. The solution I have created is very simple and leaves a very small footprint in your SharePoint environment, so it’s easy to roll back to return your environment to a supportable state, or install future Service Packs.

The solution I’ve created consists of a Server Control and a custom aspx page. The Server Control is placed on the newsbweb.aspx page that is used to create SharePoint sites from a web browser.  The Server Control looks at the URL of the page being requested to determine if the request was made from a My Site.  If the Server Control finds that the request was initiated from a My Site it redirects the user to the custom ASPX page that lets them know they cannot create a sub site under a My Site.  The page has a link to return to the My Site, and it looks just like the other SharePoint pages because it uses the same application.master file.  If you change application.master the look and feel of the custom ASPX page will change along with all the other pages in the layouts directory.

You can download the VS.NET 2005 solution containing the code for the Server Control and the custom aspx page here.

To implement the solution follow these steps:

  1. Load the VS.NET 2005 solution named Custom.SharePoint.WebControls and build it.
  2. Copy the Custom.SharePoint.WebControls.dll file to the bin directory corresponding to the web site serving up your My Sites.
    1. For example, the My Site for the administrator on my development machine has a URL like this:
      http://moss-b2:30250/personal/administrator/default.aspx
    2. Therefore, the corresponding path on the file system to the bin directory for this web site looks like this:
      C:InetpubwwwrootwssVirtualDirectories30250bin
  3. Next, edit the web.config file corresponding to the web site serving up your my Sites and add the SafeControl entry to register the assembly with SharePoint.
    1. You will find the SafeControl tag at the end of the AssemblyInfo.cs file in the Custom.SharePoint.WebControls project.
      1. It looks like this:
        <SafeControl Assembly=”Custom.SharePoint.WebControls,Version=1.0.0.0,Culture=neutral” Namespace=”Custom.SharePoint.WebControls” TypeName=”*” Safe=”True” />
      2. Copy and paste this value into the SafeControls section in the web.config file.
      3. Save the web.config file.
  4. Put the CanNotCreateMySiteSubSite.aspx file into the following directory on your SharePoint server:
    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS
  5. Make a backup of your existing newsbweb.aspx file which you will find in the following directory on your SharePoint server:
    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS
  6. Finally, copy the newsbweb.aspx file into the following directory on your SharePoint server:
    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS

To test the solution, perform the following steps:

Open IE and navigate to your my Site.
Click Site Actions
Click Create
Click Sites and Workspaces
Notice the following page appears

That’s all there is to it.