Q:

Global variables in SharePoint

Is it possible to define a global variable in SharePoint 2010 and then reference it in menus and server-side pages? We currently have a menu item on all 30+ web sites that points to the existing intranet home but will need to change it to point to the new one. Is it possible to set this to a variable defined in global.asax? Is there another way to change the menu item globally?
Thank you.

A:

The recommended way to do this is to use PropertyBag (key/value pairs) through the Properties of SPFarm, SPSite.RootWeb (for root site of site collections), SPWeb, SPList etc (depending upon the scope that you need).                
Managing Custom Configuration Options for a SharePoint Application
Update code example:
// ...inside web app feature activation code
SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

string existingValue = ... //get existing value from menu
webApp.Properties.Add("settingkey", existingValue);

// reference property later
string savedProperty = webApp.Properties["settingkey"];

Accessing SPWeb.Properties was just as easy except that I referenced the web application differently.  Since the feature is scoped to the web, the Feature.Parent will be an SPWeb instance instead of SPWebApplication.  Follow this pattern instead.
SPWeb web = (SPWeb)properties.Feature.Parent;
web.Properties.Add("settingkey", existingValue);

A:

Another option is to use Chris O'Brien Config Store (in CodePlex). Essentially it is a SharePoint list that contains your variables and values that can be accessed programatically. It also deals with caching so it doesn't have to retrieve the value every time. There's some installation and configuration hassles to be aware of (like modifying web.config ) but generally it works perfectly well. The clear advantage here is the user experience with access to the SharePoint list to perform CRUD operations on the variables.
Check it out in Code Plex here. And you know it is quality as Chris O'Brien is a legend in the SP space.

