Showing posts with label web.config. Show all posts
Showing posts with label web.config. Show all posts

Tuesday 1 May 2012

Storing Application Level Setting

Problem:  In a large On Premise farm holding several web applications (web app) I have multiple custom coded applications per web app. 

Initial Hypothesis:
  • Storing the custom apps config settings in the web config is at the wrong level and dangerous to modify even using SharePoint features. 
  • Using a list is an option however configuration could span site collections.  Additionally, security would need to be set and access granted to the appropriate people on the config list - still me favourite option especially when adding caching.
  • I have also use property bags but have need to maintain this via PowerShell.  A lot of developers like this option but without UI I felt it was not worth the effort to use/maintain and document this over using web.configs. 
Resolution:
The CodePlex project "SharePoint Property Bag Setting 2010" (PBS2010) is a great tool for replacing the developers technique of using the web.config.  The package is deployed at farm level and administration screens are provided on the Central Administration site for the farm.  PBS2010 can be extended to allow Site Collection administrators to edit the settings themselves but if this is required I would use a configuration list at the root SPWeb for the Site collection.  This is a nice codeplex project that I will definitely leverage going forward.


Below is a Powershell snippet to add a property to the property bag on the default SPWeb on a site collection:
$url= 'http://me.demo.dev/sites/PaulBeck'
$site = Get-SPSite($url)
$rootWeb = $site.RootWeb
$rootWeb.AllProperties.Add("Age","25")   # Sure Pal
$rootWeb.Update()
$ht = $rootWeb.AllProperties  # Display the hash table

Update 2015-12-15:  You can also append the url and view the RSS feed to see property bag values
http://me.demo.dev/sites/PaulBeck/_api/web/allproperties

Also See:
Microsoft have a very nice code block for setting and getting property bag settings.
http://msdn.microsoft.com/en-us/library/ff798340.aspx
It uses a unique naming convention which I'm not too happy with but I guess it so dev's don't accidentally modify or delete property bag setting set by the product.

Monday 4 July 2011

Web.config change

Overview: Change all the web.configs for all web applications on the farm except the Central Admin web application.

Tip: Use the id attribute as shown in the yellow box, it will ensure there are no duplicates created by reactivating the web.config.

Tuesday 26 October 2010

Updating the web.config

Problem: Updating the web.config by hand means you need to implement the change on each web servers web.config, so in a load balanced environment you need to do the change several times which leaves is open to mistakes and in the event of a rebuild or adding a new server, each web.config needs to be updated.

Hypothesis: You can either use a declarative approach or a programmatic approach.  Approaches on MSDN

Declarative approach is show on MSDN as the supplemental .config file You can implement the change using the ststadm cmd copyappbincontent or use a feature receiver
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
var webApp = (SPWebApplication)properties.Feature.Parent;
webApp.WebService.ApplyApplicationContentToLocalServer();
}
Note: The feature must be scoped at "Farm" or "WebApplication" level otherwise you will get a Security exception, which makes sense.  RunWithElavatedPrivileges won't stop the error.

Resolution:  The declarative approach adds whatever is in the supplemenal config to the web.config, it does not check if it's already there so it is an option for a 1 off hidden feature however a better approach is to use an xml file that has a feature receiver that activates and deactivates the changes for maximum control.

More Info:
Additional information on using the declaritive approach.
Joel Jeffery's blog has a post on modifying your web.config programatically
Update 13 Dec 2010 - http://www.spdavid.com/category/SharePoint-2010.aspx

Thursday 29 July 2010

Custom error and call stack info is not showing on my SP dev machine

Problem: I have turned my web.config file customErrors mode to "Off" however the error is telling me to turn it off or RemoteOnly. Therefore my screen is not showing me the problem. You can debug but the feedback is not provided on the erring SP page.
Hypothesis: Changing the web.config in the IIS SharePoint 2010 web site does not take effect. Ensure the web.config is correct and ensure other related web.configs used by the site are updated.
Resolution: Update the following 3 web.configs:

  • 14\CONFIG
  • 14\TEMPALTE\LAYOUTS
  • Current IIS web.config
web.configs should read:
customErrors mode="Off" />
SafeMode MaxControls="200" CallStack="true" ... AllowPage LevelTrace="true">
compilation batch="false" debug="true" >
More Info:

http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/2673ae4e-0b26-42ba-a158-1ceb63985721
http://blogs.msdn.com/b/amitsh/archive/2007/11/01/why-i-am-not-able-turn-off-customerrors.aspx