HttpRuntime類


  HttpRuntime在ASP.NET處理請求中負責的是創建HttpContext對象以及調用HttpApplicationFactory創建HttpApplication。

  其定義如下:

    public sealed class HttpRuntime
    {
        public HttpRuntime();
        //獲取 System.Web.HttpRuntime 所在的應用程序域的應用程序標識。
        public static string AppDomainAppId { get; }
        //獲取承載在當前應用程序域中的應用程序的應用程序目錄的物理驅動器路徑。
        public static string AppDomainAppPath { get; }
        //獲取包含承載在當前應用程序域中的應用程序的目錄的虛擬路徑。
        public static string AppDomainAppVirtualPath { get; }
        //獲取 System.Web.HttpRuntime 實例所在應用程序域的域標識。
        public static string AppDomainId { get; }
        //獲取 ASP.NET 客戶端腳本文件的文件夾路徑。
        public static string AspClientScriptPhysicalPath { get; }
        //獲取 ASP.NET 客戶端腳本文件的虛擬路徑。
        public static string AspClientScriptVirtualPath { get; }
        //獲取安裝 ASP.NET 可執行文件的目錄的物理路徑。
        public static string AspInstallDirectory { get; }
        //獲取當前應用程序的 /bin 目錄的物理路徑。
        public static string BinDirectory { get; }
        //獲取當前應用程序的 System.Web.Caching.Cache。
        public static Cache Cache { get; }
        //獲取安裝公共語言運行時可執行文件的目錄的物理路徑。
        public static string ClrInstallDirectory { get; }
        //獲取 ASP.NET 存儲當前應用程序的臨時文件(生成的源、編譯了的程序集等)的目錄的物理路徑。
        public static string CodegenDir { get; }
        //獲取一個值,該值指示應用程序是否映射到通用命名約定 (UNC) 共享。如果應用程序映射到 UNC 共享,則為 true;否則,為 false。
        public static bool IsOnUNCShare { get; }
        //獲取當前應用程序的 Machine.config 文件所在目錄的物理路徑。
        public static string MachineConfigurationDirectory { get; }
        //獲取一個值,該值指示當前應用程序是否在 IIS 7.0 的集成管線模式下運行。如果應用程序在集成管線模式下運行,則為 true;否則為 false。
        public static bool UsingIntegratedPipeline { get; }
        //從緩存中移除所有項。
        public static void Close();
        //返回與代碼組關聯的權限集。System.Security.NamedPermissionSet 對象,如果不存在任何權限,則為 null。
        public static NamedPermissionSet GetNamedPermissionSet();
        //驅動所有 ASP.NET Web 處理執行。參數: wr: 當前應用程序的 System.Web.HttpWorkerRequest。
        public static void ProcessRequest(HttpWorkerRequest wr);
        //終止當前應用程序。應用程序在下次接收到請求時重新啟動。
        public static void UnloadAppDomain();
    }

  這里主要選擇UnloadAppDomain()方法以及Cache來說。

  1、HttpRuntime.Cache

  • HttpRuntime.Cache 相當於就是一個緩存具體實現類,這個類雖然被放在了 System.Web 命名空間下了。但是非 Web 應用也是可以拿來用的。
  • HttpContext.Cache 是對上述緩存類的封裝,由於封裝到了 HttpContext ,局限於只能在知道 HttpContext 下使用,即只能用於 Web 應用。

  Page.Cache或HttpContext.Cache, 實際上都是HttpRuntime.Cache的快捷方式,Page.Cache訪問了HttpContext.Cache,而HttpContext.Cache又直接訪問HttpRuntime.Cache

  2、HttpRuntime.UnloadAppDomain()

  靜態方法 UnloadAppDomain() 可以讓我們用代碼重新啟動網站。 通常用於用戶通過程序界面修改了一個比較重要的參數,這時需要重啟程序了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM