想在一个fucntion.cs中建立一个静态的函数判断函数但是不能在static中使用session和response这几个东东c:\inetpub\wwwroot\yq_work\class\function.cs(64): 非静态的字段、方法或属性“System.Web.UI.Page.Response”要求对象引用c:\inetpub\wwwroot\yq_work\class\function.cs(62): 非静态的字段、方法或属性“System.Web.UI.Page.Session”要求对象引用
请问大伙有什么方法???

解决方案 »

  1.   

    那就在需要使用的这个方法里面带上一个参数System.Web.UI.Page page,然后需要的时候写page.Session和page.Response就可以
      

  2.   

    当然今后在其他页面要用这个函数的时候呢,也得带上当前的Page
      

  3.   

    那就在需要使用的这个方法里面带上一个参数System.Web.UI.Page page,然后需要的时候写page.Session和page.Response就可以
      

  4.   

    using System.Web.SessionState;
    HttpContext.Current.Session.Add("UserID",ds.Tables[0].Rows[0].ItemArray[0].ToString());
      

  5.   

    你考虑一下 static 的生存周期,就能明白为什么不能用 session 了 :)
      

  6.   

    public static string checkadmin(string str,string url)
    {
    if (Session["flag"] == null)
    {
    Response.Redirect(url);
    }
    else
    { }
    }哪位老大告诉我要怎么改
      

  7.   

    public static string checkadmin(System.Web.UI.Page page,string str,string url)
    {
    if (page.Session["flag"] == null)
    {
    page.Response.Redirect(url);
    }
    else
    { }
    }
      

  8.   

    public static string checkadmin(string str,string url)
    {
    System.Web.UI.Page page; if (page.Session["flag"] == null)
    {
    page.Response.Redirect(url);
    //必须要返回值?
    }
    else
    { }
    }第一个问题已解决了,想再请教一下,一会结分
    这个返回值该怎么办,事实上我并不想要返回值
      

  9.   

    知道了public static void checkadmin(System.Web.UI.Page page,string str,string url)谢谢 skytear(将进酒) (现在结分