首页 > 代码库 > (九)HttpContextBase 等类

(九)HttpContextBase 等类

  在进行 ASP.NET MVC 开发的时候使用 ***Base 结尾的类,不要使用 ASP.NET 原生的类。

  (1)在 Controller 中的 HttpContext 是一个 HttpContextBase 类型的属性,是对 System.Web.HttpContext 类型的封装。在 ASP.NET MVC 中不推荐直接使用 System.Web.HttpContext。

  (2)HttpContextBase 类直接”单元测试“,而 System.Web.HttpContext 不能。

  (3)不推荐使用 HttpContextBase.Current,而是随随传递。

  (4)HttpContextBase 的 Request, Response 属性都是 HttpRequestBase, HttpResponseBase 类型,Session等也是如此。

  (5)如果一定要使用 HttpContext 的话,要加上 namespace,即 System.Web.HttpContext。

(九)HttpContextBase 等类