我用的是.net2.0
一个工程有两个模块,一个是web,一个是类库。
web中的数据访问都是调用的类库。我想知道如何在类库中直接调用session,怎么弄?

解决方案 »

  1.   

    System.Web.HttpContext.Current.Session["xx"] ??
      

  2.   

    System.Web.HttpContext.Current.Session["loginid"].ToString();
      

  3.   

    可以用System.Web.HttpContext.Current.Session
      

  4.   

    类中引用不了HttpContext这个。。
      

  5.   

    最好稍微做点设计决策、分个层次,类库中不应该知道Session以及去关心Session中保存什么不保存什么,只应该通过类的属性和方法的参数来直截了当的取得数据。
      

  6.   

    类中引用不了HttpContext这个。。
    ————————————————————————————————————————
    1. 引用System.Web.dll。
    2. using System.Web
    3. 给类传递一个 HttpContext 类型的参数。不过,最好直截了当地传递类的功能所需要的参数,例如一个方法是判断用户权限的,直接传递user类型和module类型,而不要寄希望于远远超过需要的那些对象。
      

  7.   

    直接传递user类型和module类型  -->  直接传递user类型和module类型的参数
      

  8.   

    System.Web.HttpContext.Current.Response.Redirect("xxx.aspx");
    System.Web.HttpContext.Current.Server.Transfer("xxx.aspx");
      

  9.   

    送分http://community.csdn.net/Expert/topic/4927/4927379.xml?temp=.6112329
      

  10.   

    Public Sub New()
                          '判断session
                If Session.Item("login").ToString <> "" Then
                    Session.Timeout = 20
                Else
                    MsgBox("用户未登录!")
                    Response.Redirect("index.aspx")            End If        End Sub
        End Class
      

  11.   

    System.Web.HttpContext.Current.Session[""] 
      

  12.   

    System.Web.HttpContext.Current.Response.Redirect("xxx.aspx");
    System.Web.HttpContext.Current.Server.Transfer("xxx.aspx");HttpContext.Current表示当前的请求  里面可以用Response Server Session 等类
      

  13.   

    赋值就得了
    不要在类里面用session吧
      

  14.   

    System.Web.HttpContext.Current.Session["loginid"].ToString();
      

  15.   

    顶你复习写下。 
    System.Web.HttpContext.Current.Server.Transfer("");
    System.Web.HttpContext.Current.Session["djfkd"].ToString();