NullReferenceException in Sitecore.ExperienceExplorer.Business.Pipelines .HttpRequest.EnableExperienceModePipeline.Process

Recently I was upgrading a site to Sitecore 8.2.1, and I received the following error:

Okay, WTF? There’s not a lot of information about this error, and I’d never seen it before. I ended up doing my usual trick – decompiling Sitecore to see what this method does. Here’s what I found…

…and the bit underlined in red set my “stupidity radar” screaming. This line is:

string database = SiteContext.GetSite(Settings.Preview.DefaultSite).SiteInfo.Database;

If GetSite() returns null, you’ll get a null reference exception, because they didn’t bother to check the returned variable before trying to use its ‘SiteInfo’ property.

It does offer a clue, though. Our upgraded system lacks a site called ‘website‘. That is, in our config, under the <sites> node, there is no <site ... > called ‘website‘. However, the DefaultSite setting in Sitecore.config still had its default value of ‘website‘.

We changed it to the name of our site, and this error was resolved.

NullReferenceException in Sitecore.ExperienceExplorer.Business.Pipelines .HttpRequest.EnableExperienceModePipeline.Process

How many sub-sites can a site have?

Last year I was working on a system where we were creating a lot of sites. I mean, tens of thousands of sites, and all within one site collection (they’d all have a few documents and tasks, but not many). Anyway, we were told by a partner’s developer that:

  • A Site Collection’s Root Site could only have 127 subsites before performance issues would start
  • Each of those subsites could have up to 2000 subsites before performance issues would start

This seemed a bit suspicious to me. I had read on MSDN about the capacity boundaries and limits, and knew about the 2000 subsites per site note:

Subsite
2,000 per site view
The interface for enumerating subsites of a given Web site does not perform well as the number of subsites surpasses 2,000. Similarly, the All Site Content page and the Tree View Control performance will decrease significantly as the number of subsites grows.

Okay, that’s fine. And I knew that the limit on the number of Sites per Site Collection is 250,000. But I couldn’t find anything about this ‘127’ subsites under the root site thing, and I couldn’t help but wonder if this was where the ‘127’ value had come from (125 x 2000 = 250,000) as I simply didn’t see why a root site should be any different to any other type of site. Thus, I decided to test it. Continue reading “How many sub-sites can a site have?”

How many sub-sites can a site have?

Site Template Descriptions and Site Descriptions

When you save a Site Template in SharePoint you can specify a Description. That’s fine – but doesn’t really seem to be used anywhere, other than a little note on the ‘Create new Site’ form (see below). I’d always assumed that it was. Well, I was wrong. Continue reading “Site Template Descriptions and Site Descriptions”

Site Template Descriptions and Site Descriptions

How to get an SPWeb object from a URL

One of the problems with SharePoint is that it’s very difficult to figure out what site is specified by a URL. After all, the URL to a particular page contains:

  • the Server
  • possibly (but not necessarily) a managed path and site collection
  • possibly (but not necessarily) a site
  • possibly (but not necessarily) a folder (such as ‘/lists/’)
  • possibly (but not necessarily) a list/library name
  • possibly (but not necessarily) a folder in a Library
  • the item itself.

Suffice to say, with all those optional bits, decomposing a URL to find the site is really hard. There is, however, a slightly obscure way of find this. You can create a site collection (SPSite) with a full URL, and then simply call OpenWeb() without any parameters to return you the site (SPWeb):

string path = "http://example/examplesite/_layouts/settings.aspx";
try
{
using (SPSite siteCollection = new SPSite(path))
{
using (SPWeb site = siteCollection.OpenWeb())
//Do something with the site
}
}
}

I found this when looking at the MSDN docs for SPSite.OpenWeb(). Check out the examples in there.

It’s a little weird that the SPSite object remembers information about how it was opened like that. But it is useful to know.

How to get an SPWeb object from a URL

How to find out what type of site a site is…

I’ve built a feature to active branding on a site including master page, navigation and themes, which I’ve been talking about a bit over the last few weeks. One issue, though is that meeting workspaces have a different master page to ‘normal’ master pages, so I need to set them to use a different ‘custom’ master page when the feature is activated. This means that my feature receiver has to ‘know’ if the site it’s being activated on is a Meeting Workspace, or some other site.

What defines the ‘type’ of a site is the template that was used in it’s creation. Continue reading “How to find out what type of site a site is…”

How to find out what type of site a site is…

Take care when adding or removing columns from Site Content Types

As mentioned before the content types on a list are actually children of the site content types. I’ve also looked at adding columns to list content types, which naturally enough doesn’t affect their parent site content types. Anyway, there are issues to consider when dealing with adding and removing list content types – I suggest you refer to this post for more information.

So what about adding and removing columns from Site Content Types – are there issues with this? Well, yes, there are (unsurprisingly). If you add a new column to a Site Content Type, you have the option to ‘Update all content types inheriting from this type’

Update Child Content Types

If you select ‘no’, then the change only applies to that Site Content Type. The next time you add that site content type to a list, the new List Content Type that is created will have the new column, but pre-existing list content types that inherit from the site content type will be unchanged.

If you select ‘yes’, then the List Content Types (or other Site Content Types) that inherit from this content type will have the new column. For the List content types, this means that there will be a new column on the list. Carrying on from an earlier example, here I’ve added a new column (‘Job Title’) to the Example Travel Expenses site content type, and updated all content types inheriting from that. If we then go an look at the List Settings page, we can see our List Content Type has a new column:

Extra List Columns 2

Great! Now what happens if I remove that column from our Site Content Type? Well, again, I get the option to ‘Update all content types inheriting from this type’. If I choose no, then the existing List Content Types derived from this Site Content Type remain as they are. If I choose yes, though, I get a fairly large warning saying:

This column will be removed from all content types that are based on this type. If you are sure you want to remove this column from all content types based on this type, click OK. To remove this column from this content type only, click Cancel to close this dialog box, click No in the Update Lists and Columns section, and then click Remove.

Snappy message that:

Silly Warning Dialog

Anyway, if you click OK, that column is removed from child content types. H0wever, the column is not deleted from lists that were using those child content types. I removed the ‘Job Title’ column from my ‘Example Travel Expenses’ site content type. If we return to our list settings page, we can see that the column still exists, although it isn’t used in any content types:

Extra List Columns 3

This makes sense, as the column could actually contain data, and it could be used in multiple places throughout our sites (potentially hundreds!) However, maybe you do want to remove that column from that list, or potentially those hundreds of lists. In that case (and this is why this is important) you have to delete the ‘orphan’ column on a list by list basis. Therefore, if your content type was used in hundreds of lists, you will have to delete this extra column hundreds of times, once for each list.

Therefore, be very careful when adding or removing columns from a Site Content Type – make sure that you really want to add it (as removing it might be hard), and be aware that removing the column is not the same as deleting it in the lists that use it already.

Take care when adding or removing columns from Site Content Types