Joel's SharePoint Architect Blog

SharePoint 2010, MOSS & WSS Tips and Consultancy Tales

Subscribe Subscribe  View Joel Jeffery's profile on LinkedIn
joelblogs.co.uk | joelj.co.uk | joeljeffery.co.uk | jfdiphoenix.co.uk

Posts Tagged ‘SharePoint Architecture’

When you’re designing an Information Architecture with SharePoint in mind, there are some technical limitations and boundaries that will influence your choices in how you create Farms, Web Applications, Site Collections and Sites.

Microsoft documents 3 different main kind of limits inside SharePoint:

  1. Boundaries – these are physical limits beyond which SharePoint will not let you reach.
  2. Thresholds – these are default limits that you can increase or decrease, but there may be knock-on implications of changing these values.
  3. Supported Limits – these are empirically tested values for usage of different SharePoint artefacts beyond which it is possible and feasible to stray, but you will be out of support by Microsoft.

A full list of these SharePoint limits is available on TechNet. But here are some of the main ones you’ll encounter.

SharePoint Boundaries – Maximum Values

SharePoint Boundaries

SharePoint Thresholds – Maximum Values

SharePoint Thresholds

SharePoint Supported Limits – Maximum Values

SharePoint Supported Limits

Hopefully you’ll find these to be a useful starting point when turning an Information Architecture view into a Site Hierarchy in SharePoint.

Technorati Tags: Information Architecture, SharePoint, SharePoint 2010, SharePoint Architecture

When I’m setting up a SharePoint farm, the first decision I have to make is whether to go physical or virtual. There are many reasons to go virtual:

Consolidation (bringing all your under utilised servers onto one or more physical server),

Flexibility (the ability to create a point-in-time snapshot of a machine and revert to it should something bad happen),

and also perhaps reasons of convenience (you’re mocking up a development or test environment and want to have one-for-one logical mapping between servers you develop against, and those in the eventual production environment).

There are more reasons than this, and the decision tree is vast.

Whether you’re thinking of VMware or Microsoft, or even one of the open source players in the market, here’s a video worth having a look at. This interview shows two differing clients with different needs, making different choices in platform.

But for many development scenarios, and increasingly more production environments, virtualisation makes a great way to build a server farm.

In the good old days of SharePoint 2007, you could make do with Virtual PC or Virtual Server 2005 and 32-bit hardware. Well, these days we don’t have that luxury, as SharePoint requires fully 64-bit hardware, from web front end to database.

For most virtualisation platforms, you’ll also need physical hardware that supports Intel VT / AMD Virtualisation Extensions – which is usually configurable in your machines’ BIOS.

A good platform to consider from Microsoft is either Windows 2008/R2 with the Hyper-V role, or the free Hyper-V 2008 server standalone virtualisation platform. Hyper-V is a role that you can install in Windows 2008 and 2008R2 servers. I’m often asked by developers how you’d go about installing Hyper-V on its own.

In this TechNet video, Gordon Ryan from Microsoft walks you through the steps to install the free Hyper-V 2008 on a server.

For a development machine, you could also consider Windows VHD Native Boot, and here’s link to an overview of Windows Native Boot to VHD at TechNet.

Technorati Tags: Hyper-V, SharePoint, SharePoint Architecture, Virtualisation

Continuing in my series of articles showing the many ways in which we can store configuration data for your SharePoint applications, this time we look at how to use SPPersistedObject to achieve this.

Don’t forget to check out part 1 of the series in which we find out how SPWebConfigModification can be used for persisting application configuration in SharePoint 2010.

Persistence Using SPPersistedObject

SPPersistedObjects let you store hierarchical configuration data for your application in SharePoint. An SPPersistedObject is a class you subclass. You can then add fields (not properties) to your class, attribute them with [Persisted], and SharePoint will serialise the object to Xml in the SharePoint Configuration database.

Code Snippet
  1. [GuidAttribute("8AC7737A-8A57-4DD9-A782-B0B3F4595884")]
  2. public class JoelsConfigSettings : SPPersistedObject
  3. {
  4.     public JoelsConfigSettings()
  5.     {
  6.     }
  7.  
  8.     public JoelsConfigSettings(string name, SPPersistedObject parent)
  9.         : base(name, parent)
  10.     {
  11.     }
  12.  
  13.     public JoelsConfigSettings(string name, SPPersistedObject parent, Guid id)
  14.         : base(name, parent, id)
  15.     {
  16.     }
  17.  
  18.     [Persisted]
  19.     public string Value1;
  20.  
  21.     [Persisted]
  22.     public int Value2;
  23. }

The above code creates a class with two fields (string Value1 and int Value2) which can be persisted for the current Web Application with the following code:

Code Snippet
  1. SPSite s = SPContext.Current.Site;
  2. JoelsConfigSettings settings = new JoelsConfigSettings("JoelsSettingsKey", s.WebApplication, s.ID);
  3. settings.Value1 = "Joels Value 1";
  4. settings.Value2 = 2;
  5. settings.Update();

We can later retrieve – and optionally delete – the settings by calling GetChild<> on the WebApplication object.

Code Snippet
  1. SPSite s = SPContext.Current.Site;
  2. JoelsConfigSettings settings = s.WebApplication.GetChild<JoelsConfigSettings>("JoelsSettingsKey");
  3. string value1 = settings.Value1;
  4. int value2 = settings.Value2;
  5. // optionally delete our settings
  6. settings.Delete();
  7. // but proper removal requires unprovisioning and uncaching too
  8. settings.Unprovision();
  9. settings.Uncache();

As an alternative to storing at the Web Application level, you can use a Farm object instead.

Advantages

You configuration data is stored in the SharePoint Configuration database. This means it will be backed up along with the rest of your SharePoint data – assuming you perform SharePoint backups, of course. Smile

Your data is also safe from prying eyes as there is no UI to edit these settings.

Disadvantages

There is no built in user interface to manage SPPersistedObjects. This is both a good and a bad thing: you have to provide your own way of editing the values you wish to store. To read and write these values you also need elevated privileges. There are some reports of SPPersistedObject use corrupting the Hierarchical Object Store; it’s unclear whether this is due to incorrect usage or something more flaky. Proceed with caution, and thoroughly test your code first on a virtual, scratch, SharePoint farm.

Technorati Tags: Development, SharePoint 2010, SharePoint Architecture

A common requirement in SharePoint 2010 and SharePoint 2007 developments is having somewhere to save your configuration data. Maybe you need to persist a SQL connection string, maybe you need to save the URL of your accounts system web service or perhaps you want to store settings for your web part that in some way alters the behaviour of your application.

SharePoint offers you many ways of doing this, and each has their merits. In this blog posting – the first in a series – we’ll be looking at persisting configuration data using web.config files.

Persistence Using Web.Config

This is a natural choice for ASP.NET developers. We tend to think in terms of config files when it comes to saving settings for our web-based applications.

Web.config files are also perfectly valid places to store this kind of data in SharePoint, but there are some gotchas.

Gotcha #1: When you make a change to a web.config file, it causes the app domain within the ASP.NET application pool to be recycled for that IIS application root. Any others that share the application pool will also get the rug pulled from under them – you’re effectively doing an IISRESET (albeit only on sites in your app pool), which causes an outage for several seconds, and forces ASP.NET to do a recompile next page load.

Gotcha #2: When you add a new web front end server to your SharePoint farm, it will lose settings that were manually keyed into the web.config on other servers. This is because of the Microsoft SharePoint Foundation Web Application service – the service in charge of keeping IIS in sync across your farm – can only restore web.config changes that it knows about.

Microsoft SharePoint Foundation Web Application Service - Services On This Service in Central Administration

Gotcha #3: In a multi-server farm, any changes you make to web.config on one of your web front end servers must be replicated across all web front end servers.

Gotcha #4: If you have extended your Web Application into other Zones, IIS will create multiple sites to host each Zone. Each IIS site will have its own web.config file for you to keep up to date.

So, how do we avoid these problems? Well, we can’t avoid Gotcha #1. It’s how .NET works. Any web.config changes trigger app pool recycling. But we can avoid Gotcha #2, #3 and #4.

The SPWebConfigModification Class

We can automate additions to, and removals from, the web.config file using the SPWebConfigModification class. It’s a SharePoint utility class that allows us to queue up changes to web.config, and then apply them asynchronously at SharePoint’s leisure, across each IIS site for your Web Application, and each server in your farm.

The most important benefit of doing this is that when I add a new server to my farm or otherwise have to restart the Microsoft SharePoint Foundation Web Application service, I’m guaranteed that all my web.config modifications will be applied to the server.

To use the SPWebConfigModification class, you create an instance of it and set the XPath expression to the target node in web.config you’re editing, then the name of the attribute or node to add, and lastly set the value we want to update.

Then it’s a simple matter of passing your SPWebConfigModification object to the Add()method of the WebConfigModifications collection on your target SPWebService (e.g. SPWebService.ContentService).

To write your changes to the batch, invoke Update() on your SPWebService. but note that nothing will happen until you call ApplyWebConfigModifications().

The code bellow shows the steps to add a new appSetting block to your web.config, adding a key called “mySetting” with the value “http://joelblogs.co.uk”:

   1: SPWebService service = SPWebService.ContentService;

   2:  

   3: SPWebConfigModification myModification = new SPWebConfigModification();

   4: myModification.Path = "configuration/appSettings";

   5: myModification.Name = "add [@key='mySetting'] [@value='http://joelblogs.co.uk']";

   6: myModification.Sequence = 0;

   7: myModification.Owner = "AD\JOELJ";

   8: myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

   9: myModification.Value = "<add key='mySetting' value='http://joelblogs.co.uk' />";

  10: service.WebConfigModifications.Add(myModification);

  11:  

  12: /*Call Update and ApplyWebConfigModifications to save changes*/ 

  13: service.Update();

  14: service.ApplyWebConfigModifications();

If you want to read this value later in your code, say for example in a WebPart, then you can use the ConfigurationManager.AppSettings[] collection to access configuration settings in the current web.config.

The code below shows retrieving the value of the “mySetting” key from the appSettings block of your web.config:

   1: string mySetting = ConfigurationManager.AppSettings["mySetting"].ToString();

Advantages

This technique allows you to keep your web.config files in sync, and backed up. Each time SharePoint makes a change to your web.config files, it will create a backup with a time-stamped name in the same folder. It will also ensure that any servers you add, or Zones into which you extend your Web Application, will get the correct web.config entries.

Disadvantages

There are reports that SPWebConfigModification can be flaky. It certainly had issues in SharePoint 2007; use of SPWebModification inside FeatureReceivers is discouraged as sometimes these can go awry. For use elsewhere, make sure the user running the code has administrative permissions to be able to edit the web.config files in the first place.

Links

For more information, have a look at the MSDN article on SPWebConfigModification.

Technorati Tags: Development, SharePoint 2010, SharePoint Architecture

This week I’ve been presenting at the Microsoft Architect Insight Conference 2010 in London. My first session was based upon by SharePoint 2010 BCS podcast also available on my blog. Thanks to all those who came along for the show!

The second set was about Workflow in SharePoint 2010, looking at the end-to-end story from business analyst, through designer, through to developer. We look at how each of these types of worker can use Visio 2010, SharePoint Designer 2010 and Visual Studio 2010 respectively to play a part in the overall process of creating a workflow.

SharePoint 2010 Enabling Business Agility with Workflow

Don’t forget, you can find all the podcasts in the series on iTunes – search for “joelblogs tv” and you’ll find me! :o)

Technorati Tags: SharePoint 2010, SharePoint Architecture, SharePoint Designer 2010, SharePoint Videos, Videos, Visio, Visual Studio 2010, WCF, Windows Workflow Foundation, Workflow