Skip to main content

Thinking out aloud - Dave Hunter's SharePoint Blog

Go Search
Home
Blog
  

Locations of visitors to this page


 Useful Links

  Microsoft UK events
  SharePoint 2007 on CodePlex
  SharePoint Community Portal
  SharePoint User Group
  SharePoint Community Portal
  SharePoint Pedia
  SharePoint MSDN Forums
  SharePoint University
Home > Thinking out aloud - Dave Hunter's SharePoint Blog > Posts > How To: Change a SharePoint Application Pool Programmatically
My thoughts and findings on Microsoft Information worker technologies, including MCMS and SharePoint 2007 (MOSS).
How To: Change a SharePoint Application Pool Programmatically

Central Administration has a screen allow users to change the application pool identity, but doesn't allow you to change the application pool which the web application uses.  You can modify manually by opening IIS, changing the application pool and making changes to the metabase.xml.  But how do I make these changes programmatically?

Theory

An IIS Web Site in SharePoint is represented by the SPWebApplication class http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.aspx this has a property called ApplicationPool which allows to be retrieved and set http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.applicationpool.aspx

Code

System.Uri webAppToChangeUri = new System.Uri("http://intranet");
SPWebApplication webAppToChange = SPWebApplication.Lookup(webAppToChangeUri);
webAppToChange.ApplicationPool.Name = "ALL MOSS";
webAppToChange.Update(true);

webAppToChange.Provision();

Demo

I ran this code inside a windows form, you can use this or a console application.  The current application pool and the one I want to change it to has the same identity, so I just changed the ApplicationPool Name.  If your identify is different you will need to set the Username and Password properties as well.

Before running the code the intranet web application has the following properties

Before

After I run the code, right click IIS Manager and click refresh.  I open the properties of the intranet web application and check the settings have came through.

After

That's it.

Why change the application pool?

For every application pool a w3wp process will be launched and can consume large amounts of memory.  You need to find a good balance of isolation (provided by having many application pools) and consumption of memory.  Have a look at Joel's article here http://blogs.msdn.com/joelo/archive/2007/10/29/sharepoint-app-pool-settings.aspx

  Copyright
This work is licenced under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 UK: England & Wales License
  Site Map

Comments

There are no comments yet for this post.

 Dave Hunter

I'm currently a Senior Consultant at Netstore 2e2. I specialise in Microsoft Information Worker technologies (especially MOSS, MCMS and .NET), with over 8 years of experience within this area of specialism. 

I have gained two certifications for MOSS and WSS and look to complete the full certification track soon.

View Dave Hunter's profile on LinkedIn

  Subscribe in a reader


 Latest Posts

I’m attending the first ever SharePoint Saturday in the UK31/08/2010 19:43
I’ve re-joined CIBER UK31/08/2010 19:26
I’ve been Awarded a MVP for SharePoint01/04/2010 19:49
SharePoint 2010 Training on Microsoft E-Learning15/03/2010 17:56
SharePoint UK User Group - Thursday 27th August London Meeting25/08/2009 17:56
CAML Query that filters on the current user23/07/2009 17:50
Microsoft Ramp Up Free SharePoint Developer Training22/07/2009 20:59
How To: Change a SharePoint Application Pool Programmatically07/07/2009 18:08
SharePoint Forums Topping 100 Answers06/07/2009 12:29
Find out the SharePoint Internal Name for a Column or Site Column28/05/2009 09:56
1 - 10 Next