我想写一个派生于HttpContext的类,来根据自己的需要扩展HttpContext的功能。但是写类的时候怎么不能写派生于HttpContext的类呢?
cannot derive from sealed class 'System.Web.HttpContext'

解决方案 »

  1.   

    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemwebhttpcontextclasstopic.asp
    http://msdn.microsoft.com/library/chs/default.asp?url=/library/chs/csref/html/vclrfsealed.asp
    sealed类是不能被继承的
      

  2.   

    该类是sealed的所以不能继承。
    你可以使用对象组合的方式来产生一个新类。这个新类具有所有HttpContext的功能同时还可以添加自己的功能。
      

  3.   

    cuike519(marshal(修练中...)) 
    你说的“你可以使用对象组合的方式来产生一个新类。这个新类具有所有HttpContext的功能同时还可以添加自己的功能。”能介绍下你的方法吗?万分感谢!
      

  4.   

    #region 应用程序路径属性 [如:/dd]
    /// <summary>
    /// 应用程序路径属性 [如:/dd]
    /// </summary>
    /// <res>如:/dd</res>
    public static string ApplicationPath
    {
    get
    {
    return HttpContext.Current.Request.ApplicationPath.EndsWith("/") ? "" : HttpContext.Current.Request.ApplicationPath;
    }
    }
    #endregion #region 当前上下文属性
    /// <summary>
    /// 当前上下文属性
    /// </summary>
    public static System.Web.HttpContext CurrentContext
    {
    get
    {
    return HttpContext.Current;
    }
    }
    #endregion