HostingEnvironment Class

 

Provides application-management functions and application services to a managed application within its application domain. This class cannot be inherited.

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

System.Object
  System.MarshalByRefObject
    System.Web.Hosting.HostingEnvironment

Public NotInheritable Class HostingEnvironment
	Inherits MarshalByRefObject

NameDescription
System_CAPS_pubmethodHostingEnvironment()

This API supports the product infrastructure and is not intended to be used directly from your code. Initializes a new instance of the HostingEnvironment class.

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticApplicationHost

This property supports the ASP.NET infrastructure and is not intended to be used directly from your code.

System_CAPS_pubpropertySystem_CAPS_staticApplicationID

Gets the unique identifier of the application.

System_CAPS_pubpropertySystem_CAPS_staticApplicationMonitors

Gets a group of repleacable monitor objects used by ASP.NET subsystems to maintain application health.

System_CAPS_pubpropertySystem_CAPS_staticApplicationPhysicalPath

Gets the physical path on disk to the application's directory.

System_CAPS_pubpropertySystem_CAPS_staticApplicationVirtualPath

Gets the root virtual path of the application.

System_CAPS_pubpropertySystem_CAPS_staticCache

Gets the Cache instance for the current application.

System_CAPS_pubpropertySystem_CAPS_staticInClientBuildManager

Gets a value that indicates whether the hosting environment has access to the ASP.NET build system.

System_CAPS_pubpropertySystem_CAPS_staticInitializationException

Gets any exception thrown during initialization of the HostingEnvironment object.

System_CAPS_pubpropertySystem_CAPS_staticIsDevelopmentEnvironment

Gets a value that indicats whether the current application is in a development environment.

System_CAPS_pubpropertySystem_CAPS_staticIsHosted

Gets a value indicating whether the current application domain is being hosted by an ApplicationManager object.

System_CAPS_pubpropertySystem_CAPS_staticMaxConcurrentRequestsPerCPU

Gets or sets the maximum concurrent requests per CPU.

System_CAPS_pubpropertySystem_CAPS_staticMaxConcurrentThreadsPerCPU

Gets or sets the maximum concurrent threads per CPU.

System_CAPS_pubpropertySystem_CAPS_staticShutdownReason

Returns an enumerated value that indicates why the application terminated.

System_CAPS_pubpropertySystem_CAPS_staticSiteName

Gets the name of the site.

System_CAPS_pubpropertySystem_CAPS_staticVirtualPathProvider

Gets the virtual path provider for this application.

NameDescription
System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodSystem_CAPS_staticDecrementBusyCount()

Reduces the count of busy objects in the hosted environment by one.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticImpersonate()

Impersonates the user represented by the application identity.

System_CAPS_pubmethodSystem_CAPS_staticImpersonate(IntPtr)

Impersonates the user represented by the specified user token.

System_CAPS_pubmethodSystem_CAPS_staticImpersonate(IntPtr, String)

Impersonates the user specified by the configuration settings for the specified virtual path, or the specified user token.

System_CAPS_pubmethodSystem_CAPS_staticIncrementBusyCount()

Increases the count of busy objects in the hosted environment by one.

System_CAPS_pubmethodInitializeLifetimeService()

This API supports the product infrastructure and is not intended to be used directly from your code. Gives the HostingEnvironment object an infinite lifetime by preventing a lease from being created.(Overrides MarshalByRefObject.InitializeLifetimeService().)

System_CAPS_pubmethodSystem_CAPS_staticInitiateShutdown()

Starts shutting down the web application associated with this host and removes registered objects from the system.

System_CAPS_pubmethodSystem_CAPS_staticMapPath(String)

Maps a virtual path to a physical path on the server.

System_CAPS_pubmethodSystem_CAPS_staticMessageReceived()

This method supports the ASP.NET infrastructure and is not intended to be used directly from your code.

System_CAPS_pubmethodSystem_CAPS_staticQueueBackgroundWorkItem(Action(Of CancellationToken))

[Supported in the .NET Framework 4.5.2 and later versions]

Schedules a task which can run in the background, independent of any request.

System_CAPS_pubmethodSystem_CAPS_staticQueueBackgroundWorkItem(Func(Of CancellationToken, Task))

[Supported in the .NET Framework 4.5.2 and later versions]

Schedules a task which can run in the background, independent of any request.

System_CAPS_pubmethodSystem_CAPS_staticRegisterObject(IRegisteredObject)

Places an object in the list of registered objects for the application.

System_CAPS_pubmethodSystem_CAPS_staticRegisterVirtualPathProvider(VirtualPathProvider)

Registers a new VirtualPathProvider instance with the ASP.NET compilation system.

System_CAPS_pubmethodSystem_CAPS_staticSetCultures()

Sets the current thread to the culture specified in the application configuration file.

System_CAPS_pubmethodSystem_CAPS_staticSetCultures(String)

Sets the current thread to the culture of the specified virtual path.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticUnregisterObject(IRegisteredObject)

Removes an object from the list of registered objects for the application.

NameDescription
System_CAPS_pubeventSystem_CAPS_staticStopListening

[Supported in the .NET Framework 4.5.1 only]

Occurs when the worker process or application pool associated with this host has stopped listening for new requests and will eventually shut down.

Each managed application domain contains a static instance of the HostingEnvironment class, which provides access to application-management functions and application services.

The following code example is a webpage that displays the application information available from the HostingEnvironment object.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Hosting" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    appID.Text = HostingEnvironment.ApplicationID
    appPPath.Text = HostingEnvironment.ApplicationPhysicalPath
    appVPath.Text = HostingEnvironment.ApplicationVirtualPath
    siteName.Text = HostingEnvironment.SiteName
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title>Hosting Environment Sample</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table>
        <tr>
          <td colspan="2">
            <b>HostingEnvironment Properties</b></td>
        </tr>
        <tr>
          <td>
            Application ID:
          </td>
          <td>
            <asp:Label ID="appID" runat="server" />
          </td>
        </tr>
        <tr>
          <td>
            Application Physical Path:
          </td>
          <td>
            <asp:Label ID="appPPath" runat="server" />
          </td>
        </tr>
        <tr>
          <td>
            Application Virtual Path:
          </td>
          <td>
            <asp:Label ID="appVPath" runat="server" />
          </td>
        </tr>
        <tr>
          <td>
            Site Name:
          </td>
          <td>
            <asp:Label ID="siteName" runat="server" />
          </td>
        </tr>
      </table>
    </div>
  </form>
</body>
</html>

.NET Framework
Available since 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.

Return to top
Show: