HostingEnvironment HostingEnvironment HostingEnvironment HostingEnvironment Class

Definition

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

public ref class HostingEnvironment sealed : MarshalByRefObject
public sealed class HostingEnvironment : MarshalByRefObject
type HostingEnvironment = class
    inherit MarshalByRefObject
Public NotInheritable Class HostingEnvironment
Inherits MarshalByRefObject
Inheritance
HostingEnvironmentHostingEnvironmentHostingEnvironmentHostingEnvironment

Examples

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

<%@ Page Language="C#" %>

<%@ 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">
  protected void Page_Load(object sender, EventArgs e)
  {
    appID.Text = HostingEnvironment.ApplicationID;
    appPPath.Text = HostingEnvironment.ApplicationPhysicalPath;
    appVPath.Text = HostingEnvironment.ApplicationVirtualPath;
    siteName.Text = HostingEnvironment.SiteName;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head 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>
<%@ 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>

Remarks

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

Constructors

HostingEnvironment() HostingEnvironment() HostingEnvironment() HostingEnvironment()

Initializes a new instance of the HostingEnvironment class.

Properties

ApplicationHost ApplicationHost ApplicationHost ApplicationHost

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

ApplicationID ApplicationID ApplicationID ApplicationID

Gets the unique identifier of the application.

ApplicationMonitors ApplicationMonitors ApplicationMonitors ApplicationMonitors

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

ApplicationPhysicalPath ApplicationPhysicalPath ApplicationPhysicalPath ApplicationPhysicalPath

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

ApplicationVirtualPath ApplicationVirtualPath ApplicationVirtualPath ApplicationVirtualPath

Gets the root virtual path of the application.

Cache Cache Cache Cache

Gets the Cache instance for the current application.

InClientBuildManager InClientBuildManager InClientBuildManager InClientBuildManager

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

InitializationException InitializationException InitializationException InitializationException

Gets any exception thrown during initialization of the HostingEnvironment object.

IsDevelopmentEnvironment IsDevelopmentEnvironment IsDevelopmentEnvironment IsDevelopmentEnvironment

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

IsHosted IsHosted IsHosted IsHosted

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

MaxConcurrentRequestsPerCPU MaxConcurrentRequestsPerCPU MaxConcurrentRequestsPerCPU MaxConcurrentRequestsPerCPU

Gets or sets the maximum concurrent requests per CPU.

MaxConcurrentThreadsPerCPU MaxConcurrentThreadsPerCPU MaxConcurrentThreadsPerCPU MaxConcurrentThreadsPerCPU

Gets or sets the maximum concurrent threads per CPU.

ShutdownReason ShutdownReason ShutdownReason ShutdownReason

Returns an enumerated value that indicates why the application terminated.

SiteName SiteName SiteName SiteName

Gets the name of the site.

VirtualPathProvider VirtualPathProvider VirtualPathProvider VirtualPathProvider

Gets the virtual path provider for this application.

Methods

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(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)
DecrementBusyCount() DecrementBusyCount() DecrementBusyCount() DecrementBusyCount()

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
Impersonate() Impersonate() Impersonate() Impersonate()

Impersonates the user represented by the application identity.

Impersonate(IntPtr) Impersonate(IntPtr) Impersonate(IntPtr) Impersonate(IntPtr)

Impersonates the user represented by the specified user token.

Impersonate(IntPtr, String) Impersonate(IntPtr, String) Impersonate(IntPtr, String) Impersonate(IntPtr, String)

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

IncrementBusyCount() IncrementBusyCount() IncrementBusyCount() IncrementBusyCount()

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

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Gives the HostingEnvironment object an infinite lifetime by preventing a lease from being created.

InitiateShutdown() InitiateShutdown() InitiateShutdown() InitiateShutdown()

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

MapPath(String) MapPath(String) MapPath(String) MapPath(String)

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

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MessageReceived() MessageReceived() MessageReceived() MessageReceived()

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

QueueBackgroundWorkItem(Action<CancellationToken>) QueueBackgroundWorkItem(Action<CancellationToken>) QueueBackgroundWorkItem(Action<CancellationToken>) QueueBackgroundWorkItem(Action<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.

QueueBackgroundWorkItem(Func<CancellationToken,Task>) QueueBackgroundWorkItem(Func<CancellationToken,Task>) QueueBackgroundWorkItem(Func<CancellationToken,Task>) QueueBackgroundWorkItem(Func<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.

RegisterObject(IRegisteredObject) RegisterObject(IRegisteredObject) RegisterObject(IRegisteredObject) RegisterObject(IRegisteredObject)

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

RegisterVirtualPathProvider(VirtualPathProvider) RegisterVirtualPathProvider(VirtualPathProvider) RegisterVirtualPathProvider(VirtualPathProvider) RegisterVirtualPathProvider(VirtualPathProvider)

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

SetCultures() SetCultures() SetCultures() SetCultures()

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

SetCultures(String) SetCultures(String) SetCultures(String) SetCultures(String)

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

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
UnregisterObject(IRegisteredObject) UnregisterObject(IRegisteredObject) UnregisterObject(IRegisteredObject) UnregisterObject(IRegisteredObject)

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

Events

StopListening StopListening StopListening StopListening

[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.

Applies to