Export (0) Print
Expand All

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)

public sealed class HostingEnvironment : MarshalByRefObject

The HostingEnvironment type exposes the following members.

Public methodHostingEnvironmentInfrastructure. Initializes a new instance of the HostingEnvironment class.

Public propertyStatic memberApplicationHostThis property supports the ASP.NET infrastructure and is not intended to be used directly from your code.
Public propertyStatic memberApplicationIDGets the unique identifier of the application.
Public propertyStatic memberApplicationPhysicalPathGets the physical path on disk to the application's directory.
Public propertyStatic memberApplicationVirtualPathGets the root virtual path of the application.
Public propertyStatic memberCacheGets the Cache instance for the current application.
Public propertyStatic memberInClientBuildManagerGets a value that indicates whether the hosting environment has access to the ASP.NET build system.
Public propertyStatic memberInitializationExceptionGets any exception thrown during initialization of the HostingEnvironment object.
Public propertyStatic memberIsDevelopmentEnvironmentGets a value that indicats whether the current application is in a development environment.
Public propertyStatic memberIsHostedGets a value indicating whether the current application domain is being hosted by an ApplicationManager object.
Public propertyStatic memberMaxConcurrentRequestsPerCPUGets or sets the maximum concurrent requests per CPU.
Public propertyStatic memberMaxConcurrentThreadsPerCPUGets or sets the maximum concurrent threads per CPU.
Public propertyStatic memberShutdownReasonReturns an enumerated value that indicates why the application terminated.
Public propertyStatic memberSiteNameGets the name of the site.
Public propertyStatic memberVirtualPathProviderGets the virtual path provider for this application.

Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodStatic memberDecrementBusyCountReduces the count of busy objects in the hosted environment by one.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberImpersonate()Impersonates the user represented by the application identity.
Public methodStatic memberImpersonate(IntPtr)Impersonates the user represented by the specified user token.
Public methodStatic memberImpersonate(IntPtr, String)Impersonates the user specified by the configuration settings for the specified virtual path, or the specified user token.
Public methodStatic memberIncrementBusyCountIncreases the count of busy objects in the hosted environment by one.
Public methodInitializeLifetimeServiceInfrastructure. Gives the HostingEnvironment object an infinite lifetime by preventing a lease from being created. (Overrides MarshalByRefObject.InitializeLifetimeService().)
Public methodStatic memberInitiateShutdownStarts shutting down the web application associated with this host and removes registered objects from the system.
Public methodStatic memberMapPathMaps a virtual path to a physical path on the server.
Public methodStatic memberMessageReceivedThis method supports the ASP.NET infrastructure and is not intended to be used directly from your code.
Public methodStatic memberRegisterObjectPlaces an object in the list of registered objects for the application.
Public methodStatic memberRegisterVirtualPathProviderRegisters a new VirtualPathProvider instance with the ASP.NET compilation system.
Public methodStatic memberSetCultures()Sets the current thread to the culture specified in the application configuration file.
Public methodStatic memberSetCultures(String)Sets the current thread to the culture of the specified virtual path.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberUnregisterObjectRemoves an object from the list of registered objects for the application.

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="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;

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

.NET Framework

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

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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