Archive for May, 2011

SPWebConfigModification Class

May 27, 2011 2 comments

We wanted to use SPWebConfigModification class to modify the web.config of web applications (some entries are made manually already).  Also different entries for different web applications. All these in powershell 🙂

Here is our important finding before we proceed..

  • The entries which are made in web.config that are not through this class cannot be modified/deleted using this class.
  • You can apply the modification only a particular web application by calling WebAppObject.WebService.ApplyWebConfigModifications() like our last line in the below given powershell
  • Also test to remove the entries through this class to confirm our entries are getting removed safely and to identity possible bugs in making the entries.

-> .

So, clean this mess… we have to first clear those entries manually and then put it back again through SPWebConfigModification. Now i want to read the entries from a xml file so that it easily manageable and easy to ask someone in production to execute it.

<!–entry for caching config section–>
<add name=”Caching1″ connectionString=”Initial dd Catalog=Caching;Data Source={Server name};Integrated Security=false;Uid=sqlCachingUser; Pwd=p@ssw0rd” providerName=”System.Data.SqlClient” />

Now comes our powershell

Write-Host “Enter WebApplication”
$IURL = Read-Host
Write-Host “Enter Config.xml file name”
$IConfigName = Read-Host
$IWebApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($IURL)
Write-Host “Reading the Config.xml file..”
$configFile=[xml](get-content $IConfigName)
Write-Host “Config.xml file read”
foreach($config in $configFile.WebConfigModifications.WebConfig)
$Entry = new-object  Microsoft.SharePoint.Administration.SPWebConfigModification
$Entry.Path = $config.NodePath
$Entry.Name = $config.NodeKey
$Entry.Type =[Microsoft.SharePoint.Administration.SPWebConfigModification+SPWebConfigModificationType]::EnsureChildNode
$Entry.Owner = ‘APlainTextisEnough’
$Entry.Value =  $config.NodeValue.get_InnerXml()

now execute this powershell script in SharePoint 2010 management shell. Provide the first input as the web applicaiton url for which you want to enter the modifications. And secondly provide the path to .xml file which was stored earlier like .\config.xml.

That’s it.. your modification will reflect only to the web application what you have provided.

[Update 1] If you try to apply a webconfig entry and if that is not going through successfully then most likely that entry remains in configuration database. And when you try to apply webconfig modifications sometime later, the older entry will be still attempted in web.config file. So to check what are the webconfig modifications that are being applied you can check through


Through this, you can see what are the modifications that are being applied, but may not be actually present in web.config file.

Download .xml & powershell file from here


SharePoint Cache

May 19, 2011 Leave a comment

Caching is very important to improve the performance of a site. When it comes to SharePoint, it is a kind of grey area because you don’t know how the cache headers are set or on what logic are they set. SharePoint set’s the cache header based

case 1:  Content delivered from file system (typically _layouts folder)

case 2:  Contents that are delivered from Content DB (like Doc library, Picture Library etc)

In case 1, the files that are delivered are not private. And will have max-age value set to some number (more than 30 days i believe). And all the subsequent requests to these resources will be delivered from cache. Unless until you clear the cache most of the content are delivered from cache.

In case 2,  there are two sub scenario’s one with BLOB cache enabled & one without BLOB cache enabled.

First without BLOB Cache enabled, the cache headers delivered will be something like ‘Private, Max-age:0’ & expiration will be 15 days before current date. (Don’t know why is that so). This means that cache is private (meaning that user can cache this content) and all subsequent request to this resource will be used from cache after checking with server that the content is not modified.

You can notice HTTP status codes 304 for these requests which confirms that content is not modified. Each content is generally delivered by server with ‘LatModified’ date. This means a round trip to the server is involved but no data is transferred if the content is not modified.

Even this ‘304’ status involves some operation on the server. As the content are stored in DB, only a DB query can tell if the content has modified after a specific time. So, when targeting large users (may be in ten’s of thousand) avoid this is also a good idea. And enabling BLOB cache is best option.

Now with BLOB cache, the cache is public and max-age is ‘86400’ which is 24 hours. And all the subsequent request for these resources will be from cache unless you clear the cache or if you do ctrl+f5. In this way a round trip to the server is avoided to check if the resource has been modifed or not.  And this involves some DB operation as described before.

TIP: When using Fiddler don’t press F5 to analyze the cache, because F5 behaves differently and our Content db items will be need to be verified for latest version before serving to the browser.

Hope this helps someone.

Flushing BLOB Cache

May 17, 2011 Leave a comment

We will not go through what is BLOB cache as you can find so many articles for that.  We need to flush the BLOB cache from becuase it may not work as expected and we need to flush the BLOB cache. The Microsoft article what you will get is to do this will be

But this article, i believe is missing to say one crucial information (as on 17th May 2011).  And information is that you have to execute this script on all WFE’s in your FARM. Otherwise, it is gets flushed only on the server where you execute.

One tip to identify that BLOB cache is working as expected

The images that are stored in picture library and being referenced in the page will not have cache header as “public”, if it is private or if the max-age is empty then BLOB cache is not working as expected and you flush BLOB cache. In this picture you can see,  a image named TN.jpg has cache header as ‘Private, max-age=0

Once BLOB cache is enabled and cache is flushed as mentioned in previous technet article (in all WFE’s) then the header to be expected is ‘Public’ with some max-age set.

Hope this helps someone.

Know the Build Version of SharePoint 2010

May 13, 2011 Leave a comment

Some times , you forget what CU has been installed in the FARM. At time you are given just the build version of the FARM  and you need to have same version in your environment.

Every time when i hit this situation, i use google to find it out, so here is the link (so i am not taking credit for someone’s work) where you can find build version till April 2011 CU

Categories: Administration