1 out of 3 rated this helpful - Rate this topic

ServerManager Class

IIS 7.0

Provides read and write access to the IIS 7 configuration system.

System..::..Object
  Microsoft.Web.Administration..::..ServerManager

Namespace:  Microsoft.Web.Administration
Assembly:  Microsoft.Web.Administration (in Microsoft.Web.Administration.dll)
public sealed class ServerManager : IDisposable

The ServerManager type exposes the following members.

  Name Description
Public method ServerManager()()()() Initializes a new instance of the ServerManager class by using the default path of the ApplicationHost.config file.
Public method ServerManager(String) This API supports the iisver Framework infrastructure and is not intended to be used directly from your code. Microsoft Internal Use Only.
Public method ServerManager(Boolean, String) This API supports the iisver Framework infrastructure and is not intended to be used directly from your code. Microsoft Internal Use Only.
Top
  Name Description
Public property ApplicationDefaults Gets an object that defines the default values for applications that are configured on the current server.
Public property ApplicationPoolDefaults Gets an object that defines the default values for application pools that are configured on the current server.
Public property ApplicationPools Gets a collection of application pools on the current server.
Public property SiteDefaults Gets an object that defines the default values for sites that are configured on the current server.
Public property Sites Gets the collection of Web sites that are configured on the current server.
Public property VirtualDirectoryDefaults Gets an object that defines the default values for all virtual directories that are configured on the current server.
Public property WorkerProcesses Gets a collection of worker processes on the current server.
Top
  Name Description
Public method CommitChanges Commits changes to the IIS 7 configuration system.
Public method Dispose Releases all resources used by the ServerManager class.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetAdministrationConfiguration()()()() Returns a Configuration object for the default Administration.config file.
Public method GetAdministrationConfiguration(WebConfigurationMap, String) Returns a Configuration object for the Administration.config file by using the specified WebConfigurationMap object and configuration file path.
Public method GetApplicationHostConfiguration Returns a Configuration object for the default ApplicationHost.config file.
Public method GetHashCode (Inherited from Object.)
Public method GetMetadata Returns metadata values from the server manager.
Public method GetRedirectionConfiguration Returns the configuration from the configuration manager.
Public method GetType (Inherited from Object.)
Public method GetWebConfiguration(String) Returns a Configuration object for a Web.config file by using the specified Web site name.
Public method GetWebConfiguration(String, String) Returns a Configuration object for a Web.config file by using the specified Web site name and virtual path.
Public method GetWebConfiguration(WebConfigurationMap, String) Returns a Configuration object for a Web.config file by using the specified WebConfigurationMap object and configuration file path.
Protected method MemberwiseClone (Inherited from Object.)
Public method Static member OpenRemote Creates a ServerManager object that is connected to a remote system.
Public method SetMetadata Adds or changes the metadata for the current server manager.
Public method ToString (Inherited from Object.)
Top
  Name Description
Explicit interface implemetation Private method IDisposable..::..Dispose Releases the unmanaged resources used by the ServerManager.
Top

The ServerManager object is the top-level configuration object. You can access the Application collection, Site collection, WorkerProcess collections, Binding objects, and VirtualDirectory collections from the ServerManager. The properties that the ServerManager class exposes are read-only. However, the objects that the properties of this class return provide both read and write access. Updates made to configuration objects must be explicitly written to the configuration system by using the CommitChanges method.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Memory Leak
$0 $0using (ServerManager smg = new ServerManager())$0 $0$0 $0 $0This causes a SERIOUS memory leak - I've been using it for a while in a Windows Service to monitor a web site.$0 $0
Memory leak confirmed.
$0Confirmed. This code causes a severe memory leak.$0
Dispose bug

The following code produces memory leaks. After 5 minutes of running the the Working set of the process increased linearly up to 250 MB.  Am I missing something or is this a Dispose bug?
Just to mention, is use the latest verion of Windows Server 2008 R2, Visual Studio 2010, .NET 4.0, IIS 7.5 (lates updates from Windows Updates and everything...).

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Web.Administration;
using System.Threading;

namespace testCs
{
    class Program
    {
        static void Main(string[] args)
        {   
            while (true)
            {
                try
                {
                    using (ServerManager smg = new ServerManager())
                    {
                        // smg.CommitChanges();
                        Console.WriteLine(smg.WorkerProcesses.Count);
                    }
                    // smg.Dispose();
                    // smg = null;

                }
                catch { }
                Thread.Sleep(1);
            }

        }
    }
}

 

Thanks,
Stefan