HttpRuntime 類別

定義

為目前應用程式提供一組 ASP.NET Run-Time 服務。

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

範例

下列範例示範如何取得代表目前應用程式域的 HttpRuntime 類別屬性,並將其顯示給瀏覽器。

<%@ 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 管線模型開頭使用。 方法 ProcessRequest 會驅動所有後續 ASP.NET Web 處理。

例如, HttpRuntime 頁面開發人員可以使用類別屬性來找出目前應用程式域的相關資訊,例如診斷用途。 建立自訂進程管線或自訂裝載環境的開發人員應該從 衍生自 或 SimpleWorkerRequest 類別的 HttpWorkerRequest 類別呼叫 ProcessRequest 方法。

建構函式

HttpRuntime()

初始化 HttpRuntime 類別的新執行個體。

屬性

AppDomainAppId

取得 HttpRuntime 存在的應用程式定義域的應用程式識別。

AppDomainAppPath

取得目前應用程式定義域裡裝載 (Host) 應用程式的應用程式目錄的實體磁碟路徑。

AppDomainAppVirtualPath

取得包含目前應用程式定義域裡裝載應用程式的目錄的虛擬路徑。

AppDomainId

取得 HttpRuntime 執行個體所在之應用程式定義域的定義域識別。

AspClientScriptPhysicalPath

取得 ASP.NET 用戶端指令碼檔的資料夾路徑。

AspClientScriptVirtualPath

取得 ASP.NET 用戶端指令碼檔的虛擬路徑。

AspInstallDirectory

取得 ASP.NET 可執行檔安裝的目錄的實體路徑。

BinDirectory

取得目前應用程式的 /bin 目錄的實體路徑。

Cache

取得目前應用程式的 Cache

ClrInstallDirectory

取得 Common Language Runtime 可執行檔安裝的目錄的實體路徑。

CodegenDir

取得 ASP.NET 儲存目前應用程式的暫存檔 (產生的來源、編譯的組譯等) 的目錄實體路徑。

IISVersion

取得裝載此應用程式的 IIS 版本。

IsOnUNCShare

取得值,指出應用程式是否對應至通用命名規範 (Universal Naming Convention,UNC) 共用。

MachineConfigurationDirectory

取得目前應用程式的 Machine.config 檔所在位置的目錄的實體路徑。

TargetFramework

取得目前 Web 應用程式以之為設計目標的 .NET Framework 版本。

UsingIntegratedPipeline

取得值,指出目前的應用程式是否在 IIS 7.0 的整合管線模式中執行。

WebObjectActivator

取得或設定相依性插入支援的 IServiceProvider 執行個體。

方法

Close()

關閉 HttpRuntime 執行個體。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetNamedPermissionSet()

傳回與程式碼群組關聯的使用權限集合。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ProcessRequest(HttpWorkerRequest)

驅動所有 ASP.NET Web 處理的執行。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
UnloadAppDomain()

終止目前的應用程式。 下次收到應用程式的要求時,就會重新啟動。

適用於

另請參閱