zoukankan      html  css  js  c++  java
  • 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() 可以让我们用代码重新启动网站。 通常用于用户通过程序界面修改了一个比较重要的参数,这时需要重启程序了。

  • 相关阅读:
    LintCode "Maximum Gap"
    LintCode "Wood Cut"
    LintCode "Expression Evaluation"
    LintCode "Find Peak Element II"
    LintCode "Remove Node in Binary Search Tree"
    LintCode "Delete Digits"
    LintCode "Binary Representation"
    LeetCode "Game of Life"
    LintCode "Coins in a Line"
    LintCode "Word Break"
  • 原文地址:https://www.cnblogs.com/feng-NET/p/4540648.html
Copyright © 2011-2022 走看看