Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
WmiWebEventProvider Class

WmiWebEventProvider Class

Implements an event provider that maps ASP.NET health-monitoring events to Windows Management Instrumentation (WMI) events.

Namespace:  System.Web.Management
Assembly:  System.Web (in System.Web.dll)

public class WmiWebEventProvider : WebEventProvider

The WmiWebEventProvider type exposes the following members.

Public methodWmiWebEventProviderInitializes a new instance of the WmiWebEventProvider class.

Public propertyDescriptionGets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs). (Inherited from ProviderBase.)
Public propertyNameGets the friendly name used to refer to the provider during configuration. (Inherited from ProviderBase.)

Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFlushRemoves all events from the provider's buffer. (Overrides WebEventProvider.Flush().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeSets the initial values for this object. (Overrides ProviderBase.Initialize(String, NameValueCollection).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodProcessEventProcesses the event passed to the provider. (Overrides WebEventProvider.ProcessEvent(WebBaseEvent).)
Public methodShutdownPerforms tasks associated with shutting down the provider. (Overrides WebEventProvider.Shutdown().)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

ASP.NET health monitoring allows production and operations staff to manage deployed Web applications. The System.Web.Management namespace contains the health-event types responsible for packaging application health-status data and the provider types responsible for processing this data. It also contains supporting types that help during the management of health events.

ASP.NET uses this class to map health-monitoring events to WMI events. To enable the delivery of ASP.NET health-monitoring events to the WMI subsystem, you must configure the WmiWebEventProvider class by adding the appropriate settings in the <healthMonitoring> section of the configuration file.

The information contained in the Aspnet.mof file describes the parameters of the WMI events raised when ASP.NET health-monitoring events are routed to the WmiWebEventProvider class and mapped into WMI events. The Aspnet.mof file is stored in the .NET Framework build directory, for example %windir%\Microsoft.NET\Framework\BuildNumber. For more information about reporting health-monitoring events as WMI events, see Using WMI to Deliver ASP.NET Health-Monitoring Events.


In most cases you will be able to use the ASP.NET health-monitoring types as implemented, and you will control the health-monitoring system by specifying values in the <healthMonitoring> configuration section. You can also derive from the health-monitoring types to create your own custom events and providers. For an example of creating a custom provider, see How to: Implement the Health Monitoring Custom Provider Example.

The following example shows how to create a consumer of WMI events issued by ASP.NET health monitoring as a result of Web-application health events.


The WmiWebEventProvider class and the health event types to monitor are already configured by default. The only thing you need to do is to define the rule for all the health events. Remember that the health events are not dispatched to the WmiWebEventProvider provider by default.

using System;
using System.Management;

namespace SamplesAspNet
    // Capture WMI events associated with  
    // ASP.NET health monitoring types.  
    class SampleWmiWebEventListener
        //Displays event related information. 
        static void DisplayEventInformation(
            ManagementBaseObject ev)

            // It contains the name of the WMI raised  
            // event. This is the name of the  
            // event class as defined in the  
            // Aspnet.mof file. 
            string eventTypeName;

            // Get the name of the WMI raised event.
            eventTypeName = ev.ClassPath.ToString();

            // Process the raised event. 
            switch (eventTypeName)
                // Process the heartbeat event.   
                case "HeartBeatEvent":
                    Console.WriteLine("\tProcess: {0}", 
                    Console.WriteLine("\tApp: {0}", 
                    Console.WriteLine("\tWorkingSet: {0}", 
                    Console.WriteLine("\tThreads: {0}", 
                    Console.WriteLine("\tManagedHeap: {0}",
                    Console.WriteLine("\tAppDomainCount: {0}",

                // Process the request error event.  
                case "RequestErrorEvent":
                    Console.WriteLine("Url: {0}", 
                    Console.WriteLine("Path: {0}", 
                    Console.WriteLine("Message: {0}", 
                    Console.WriteLine("Stack: {0}", 
                    Console.WriteLine("UserName: {0}", 
                    Console.WriteLine("ThreadID: {0}", 

                // Process the application lifetime event.  
                case "ApplicationLifetimeEvent":
                    Console.WriteLine("App Lifetime Event {0}", 


                // Handle events for which processing is not 
                // provided. 
                    Console.WriteLine("ASP.NET Event {0}",
        } // End DisplayEventInformation. 

        // The main entry point for the application. 
        static void Main(string[] args)
            // Get the name of the computer on  
            // which this program runs. 
            // Note. The monitored application must also run  
            // on this computer. 
            string machine = Environment.MachineName;

            // Define the Common Information Model (CIM) path  
            // for WIM monitoring.  
            string path = String.Format("\\\\{0}\\root\\aspnet", 

            // Create a managed object watcher as  
            // defined in System.Management. 
            string query = "select * from BaseEvent";
            ManagementEventWatcher watcher =
                new ManagementEventWatcher(query);

            // Set the watcher options.
            TimeSpan timeInterval = new TimeSpan(0, 1, 30);
            watcher.Options = 
                new EventWatcherOptions(null,
                timeInterval, 1);

            // Set the scope of the WMI events to  
            // watch to be ASP.NET applications.
            watcher.Scope = 
                new ManagementScope(new ManagementPath(path));

            // Set the console background.
            Console.BackgroundColor = ConsoleColor.Blue;
            // Set foreground color.
            Console.ForegroundColor = ConsoleColor.Yellow;
            // Clear the console.

            // Loop indefinitely to catch the events.
                "Listener started. Enter CntlC to terminate");

            while (true)
                    // Capture the WMI event related to  
                    // the Web event.
                    ManagementBaseObject ev = 
                    // Display the Web event information.

                    // Prompt the user.

                catch (Exception e)
                    Console.WriteLine("Error: {0}", e);



The following example is a configuration file excerpt that shows a <healthMonitoring> configuration section that enables ASP.NET to use the WmiWebEventProvider provider to process all health-monitoring events.

      name="Using Wmi"
      eventName="All Events" 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2015 Microsoft