我引用了一个类库,类库我已经转换为Web应用程序,为什么在类库里引用Application("cnstr")时会提示“HttpContext 不可用。此类只能用于 ASP.NET 请求的上下文中。”这个错误呢?

解决方案 »

  1.   

    类库里不能用HttpContext 类。appliction 是他的一个属性
      

  2.   

    类库中已经引用了System.Web,这个类库是WebService,在类的顶部引用了System.Web.Services.WebService在Web应用程序调用到类库中Application("cnstr")时提示上述错误。
      

  3.   

    结构大概是这样的Imports System.Web.ServicesPublic Class myClass    Inherits System.Web.Services.WebService
      Public Function GetConnection() As Boolean

    dim conn As String =Application("cnstr").ToString()  '出错位置

    ... End FunctionEnd Class
      

  4.   

    引用了System.Web.Services就不用引用它了吧
      

  5.   

    HttpContext context=HttpContext.Current;
    context.Request
    context.Response
    context.Applicationtry to it
      

  6.   

    “类库我已经转换为Web应用程序”?Web应用程序是由web服务器系统启动的,你类库是不能决定调用它的程序是不是Web应用程序的。
      

  7.   


    试了一下,HttpContext.Current竟然是null
      

  8.   


    其实这是个WebService,编译后生成DLL,我想是不是因为没被当成Web应用程序才不支持HttpContext的?所以我转换了一下,可能这是无关紧要的。
      

  9.   

    HttpContext.Current为null,是不是引用的DLL和原Web程序不在一个进程?这是为何?
      

  10.   

    我是在新开的线程里调用的,Application不能在多线程共享吗
      

  11.   

    是在网站中使用的,在读取Email时,调用到DLL的某个方法,其中使用了多线程。