in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Todd Baginski's SharePoint 2003 and MOSS 2007 Blog

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:\Inetpub\wwwroot\wss\VirtualDirectories\30250\bin
  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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
  5. Make a backup of your existing newsbweb.aspx file which you will find in the following directory on your SharePoint server:
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
  6. Finally, copy the newsbweb.aspx file into the following directory on your SharePoint server:
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS

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.

Comments

 

Greg said:

Are you sure these instructions are accurate?  When I follow these steps, it keeps pointing to the newsbweb.aspx file.

July 5, 2007 10:34 AM
 

Julian said:

There is a missing file newspweb.aspx

July 30, 2007 12:14 AM
 

lmp8874 said:

How can I get a copy of the newspweb.aspx file?

August 7, 2007 12:47 PM
 

tbaginski said:

I updated the archive and added the newsbweb.aspx file.  Thanks for pointing out that it was missing.

August 7, 2007 7:48 PM
 

Internet Business Training Program said:

Your post have brought me a greater insight into a deeper level of thinking for me and I just wish to say thanks.

March 31, 2008 3:28 PM
 

Simon said:

Hi Todd,

after Step 6 I just got an error when trying to create a new site from anywhere on the portal. I then swapped back to the original newsbweb.aspx and the error went away but I'm back where I started.

I noticed that when I built the solution in VS2008, the solution file was modified but the Custom.SharePoint.WebControls.dll didn't change. Could that be the problem? Please help

April 28, 2008 9:54 AM
 

WorkerThread said:

I noticed that the supplied newsbweb.aspx file has hardcode server name and port values, so these need to be changed (unless your server is called moss-b2 on port 30250).

However, even after changing these, I'm getting the same problem as Simon.  Does anyone have this working?

May 6, 2008 5:02 AM
 

tbaginski said:

Let me see if I can help you out, here are a few ideas.

First, one place to look for clues are the LOG files in the 12/LOGS directory.  These files contain detailed error messages that usually help you solve the problem.  You can find a free Feature that allows you to view these log files within central administration here www.codeplex.com/.../ProjectReleases.aspx the one you want is the second one in the list (Log Viewer).

Another thing you could do would be to debug the WebControl on the page to determine which line of code is failing.

Finally, make sure that the URL and PORT you specify in the following TAG in the newsbweb.aspx file match the URL and port of the SharePoint Web Application that hosts your MySites.

<CustomSharePointWebControls:CreateMySiteSubSitePreventer ServerName="moss-b2" Port="30250" RedirectPageName="CanNotCreateMySiteSubSite.aspx" runat="server" />

May 6, 2008 11:39 AM
 

sriniko said:

Hi there,

This post seems to be a great one. One question - How can I prevent the mysite owner to create document and list libraries in his mysite ?

Any help

Thanks in advance

Sriniko

June 2, 2008 12:26 AM
 

Anurag said:

Hi Greg,

I am trying to create new .aspx page under the SharePoint site. I am followed the given steps.

1.Create Web Application in VS2008 and new page(called Demo.aspx) under it.

2.In code behind implement the OnPreInit() method.

3. In aspx page place the <asp:content contentplaceholderid =PlaceHolderMain runat=server/> and deployed in LAYOUTS/Test/Demo.aspx.

4.Signed the assembly and deployed in GAC.

I think I am following the step to use custom aspx page under sharepoint environment.

Still It throw error..(Content Controls are allowed only in content page that reference the master page)....

You help will be highly appreciated....

Thanks,

Anurag

August 10, 2008 12:12 PM
 

Biblical Events Timeline said:

I have always conceived of the God of the Bible as an engineer before he is a king. Unlike any other king, he is the maker of his realm, and as a perfect being, he must clearly put perfect thought into perfect design and then into perfect form. I admit

August 17, 2008 2:03 PM

Leave a Comment

(required )  
(optional )
(required )  
Add

About tbaginski

Todd began working with WSS and SPS in the beta stages of the products, in 2003. He has architected and implemented intranets, extranets, wireless deployments, and several custom applications with the WSS and SPS platforms. Todd created the first SharePoint advanced development training curriculum in the training industry for Microsoft SharePoint Portal Server 2003 and taught his first class in December of 2003. Todd also created the first advanced development training curriculum for Microsoft Office SharePoint Server (MOSS) 2007 and taught parts of this curriculum while MOSS was still in the Beta 1 Technical Refresh stage! Two versions in a row, Todd has broken ground in the training industry by being the first to offer advanced development training for SharePoint! Todd speaks at many SharePoint conferences including SharePoint Connections, the MS SharePoint Conference, and the upcoming TechEd 2008 Developers Conference. He has also spoken at Microsoft events at the Microsoft offices in both Denver, Colorado and Minneapolis, Minnesota. He has also presented several sessions at the Rocky Mountain SharePoint User's Group. He enjoys spending time with his wife and their dogs, playing and coaching lacrosse, playing hockey, riding his bike in the Rocky Mountains, and skiing every chance he gets.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts