我使用的是与jQuery的asp.net pagemethods ....如何获取静态方法在C#中的会话变量的值?如何在静态方法中获取会话变量的值?
protected void Page_Load(object sender, EventArgs e)
{
Session["UserName"] = "Pandiya";
}
[WebMethod]
public static string GetName()
{
string s = Session["UserName"].ToString();
return s;
}
当我编译这个我得到的错误:
An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Session.get'`
任何建议或任何其他?
使用HttpContext.Current这样的: HttpContext.Current.Session [ “用户名”]的ToString(); – 2016-06-11 16:01:30