HttpRuntime 類別

定義

為目前應用程式提供一組 ASP.NET Run-Time 服務。Provides a set of ASP.NET run-time services for the current application.

public ref class HttpRuntime sealed
public sealed class HttpRuntime
type HttpRuntime = class
Public NotInheritable Class HttpRuntime
繼承
HttpRuntime

範例

下列範例示範如何取得 HttpRuntime 代表目前應用程式域之類別的屬性,並將其顯示在瀏覽器中。The following example demonstrates how to get properties of the HttpRuntime class representing the current application domain and display them to the browser.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Load(Object sender, System.EventArgs e)
  {
    StringBuilder sb = new StringBuilder();
    String nl = "<br />";

    sb.Append("AppDomainAppId = " + 
      HttpRuntime.AppDomainAppId + nl);
    sb.Append("AppDomainAppPath = " + 
      HttpRuntime.AppDomainAppPath + nl);
    sb.Append("AppDomainAppVirtualPath = " + 
      HttpRuntime.AppDomainAppVirtualPath + nl);
    sb.Append("AppDomainId = " + 
      HttpRuntime.AppDomainId + nl);
    sb.Append("AspInstallDirectory = " + 
      HttpRuntime.AspInstallDirectory + nl);
    sb.Append("BinDirectory = " + 
      HttpRuntime.BinDirectory + nl);
    sb.Append("ClrInstallDirectory = " + 
      HttpRuntime.ClrInstallDirectory + nl);
    sb.Append("CodegenDir = " + 
      HttpRuntime.CodegenDir + nl);
    sb.Append("IsOnUNCShare = " + 
      HttpRuntime.IsOnUNCShare.ToString() + nl);
    sb.Append("MachineConfigurationDirectory = " + 
      HttpRuntime.MachineConfigurationDirectory + nl);

    label1.Text = sb.ToString();
  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>HttpRuntime Example</title>
  </head>
  <body>    
    <form id="form1" runat="server">
      <asp:label id="label1" runat="server"/>
    </form>
  </body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
    Dim sb As New StringBuilder()
    Dim nl As String = "<br />"

    sb.Append("AppDomainAppId = " & _
      HttpRuntime.AppDomainAppId & nl)
    sb.Append("AppDomainAppPath = " & _
      HttpRuntime.AppDomainAppPath & nl)
    sb.Append("AppDomainAppVirtualPath = " & _
      HttpRuntime.AppDomainAppVirtualPath & nl)
    sb.Append("AppDomainId = " & _
      HttpRuntime.AppDomainId & nl)
    sb.Append("AspInstallDirectory = " & _
      HttpRuntime.AspInstallDirectory & nl)
    sb.Append("BinDirectory = " & _
      HttpRuntime.BinDirectory & nl)
    sb.Append("ClrInstallDirectory = " & _
      HttpRuntime.ClrInstallDirectory & nl)
    sb.Append("CodegenDir = " & _
      HttpRuntime.CodegenDir & nl)
    sb.Append("IsOnUNCShare = " & _
      HttpRuntime.IsOnUNCShare.ToString() & nl)
    sb.Append("MachineConfigurationDirectory = " & _
      HttpRuntime.MachineConfigurationDirectory & nl)

    label1.Text = sb.ToString()

  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>HttpRuntime Example</title>
  </head>
  <body>    
    <form id="Form1" runat="server">
      <asp:label id="label1" runat="server"/>
    </form>
  </body>
</html>

備註

HttpRuntime物件是在處理 HTTP 要求的 ASP.NET 管線模型開始時使用。The HttpRuntime object is used at the beginning of the ASP.NET pipeline model that processes HTTP requests. ProcessRequest方法會驅動所有後續的 ASP.NET Web 處理。The ProcessRequest method drives all subsequent ASP.NET Web processing.

例如,網頁開發人員可以使用 HttpRuntime 類別屬性來找出目前應用程式域的相關資訊,以供診斷之用。Page developers can use the HttpRuntime class properties to find out information about the current application domain for diagnostic purposes, for example. 建立自訂進程管線或自訂裝載環境的開發人員應該 ProcessRequest 從衍生自或類別的類別呼叫方法 HttpWorkerRequest SimpleWorkerRequestDevelopers creating custom process pipeline or a custom hosting environment should call the ProcessRequest method from a class derived from the HttpWorkerRequest or SimpleWorkerRequest class.

建構函式

HttpRuntime()

初始化 HttpRuntime 類別的新執行個體。Initializes a new instance of the HttpRuntime class.

屬性

AppDomainAppId

取得 HttpRuntime 存在的應用程式定義域的應用程式識別。Gets the application identification of the application domain where the HttpRuntime exists.

AppDomainAppPath

取得目前應用程式定義域裡裝載 (Host) 應用程式的應用程式目錄的實體磁碟路徑。Gets the physical drive path of the application directory for the application hosted in the current application domain.

AppDomainAppVirtualPath

取得包含目前應用程式定義域裡裝載應用程式的目錄的虛擬路徑。Gets the virtual path of the directory that contains the application hosted in the current application domain.

AppDomainId

取得 HttpRuntime 執行個體所在之應用程式定義域的定義域識別。Gets the domain identification of the application domain where the HttpRuntime instance exists.

AspClientScriptPhysicalPath

取得 ASP.NET 用戶端指令碼檔的資料夾路徑。Gets the folder path for the ASP.NET client script files.

AspClientScriptVirtualPath

取得 ASP.NET 用戶端指令碼檔的虛擬路徑。Gets the virtual path for the ASP.NET client script files.

AspInstallDirectory

取得 ASP.NET 可執行檔安裝的目錄的實體路徑。Gets the physical path of the directory where the ASP.NET executable files are installed.

BinDirectory

取得目前應用程式的 /bin 目錄的實體路徑。Gets the physical path to the /bin directory for the current application.

Cache

取得目前應用程式的 CacheGets the Cache for the current application.

ClrInstallDirectory

取得 Common Language Runtime 可執行檔安裝的目錄的實體路徑。Gets the physical path to the directory where the common language runtime executable files are installed.

CodegenDir

取得 ASP.NET 儲存目前應用程式的暫存檔 (產生的來源、編譯的組譯等) 的目錄實體路徑。Gets the physical path to the directory where ASP.NET stores temporary files (generated sources, compiled assemblies, and so on) for the current application.

IISVersion

取得裝載此應用程式的 IIS 版本。Gets the version of IIS that is hosting this application.

IsOnUNCShare

取得值,指出應用程式是否對應至通用命名規範 (Universal Naming Convention,UNC) 共用。Gets a value that indicates whether the application is mapped to a universal naming convention (UNC) share.

MachineConfigurationDirectory

取得目前應用程式的 Machine.config 檔所在位置的目錄的實體路徑。Gets the physical path to the directory where the Machine.config file for the current application is located.

TargetFramework

取得目前 Web 應用程式以之為設計目標的 .NET Framework 版本。Gets the version of the .NET Framework that the current web application targets.

UsingIntegratedPipeline

取得值,這個值會指出目前的應用程式是否正在 IIS 7.0 的整合管線模式中執行。Gets a value that indicates whether the current application is running in the integrated-pipeline mode of IIS 7.0.

WebObjectActivator

取得或設定相依性插入支援的 IServiceProvider 執行個體。Gets or sets the IServiceProvider instance for dependency injection support.

方法

Close()

關閉 HttpRuntime 執行個體。Shuts down the HttpRuntime instance.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetNamedPermissionSet()

傳回與程式碼群組關聯的使用權限集合。Returns the set of permissions associated with code groups.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ProcessRequest(HttpWorkerRequest)

驅動所有 ASP.NET Web 處理的執行。Drives all ASP.NET Web processing execution.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
UnloadAppDomain()

終止目前的應用程式。Terminates the current application. 下次收到應用程式的要求時,就會重新啟動。The application restarts the next time a request is received for it.

適用於

另請參閱