Tôi đang sử dụng asp.net pagemethods với jQuery .... Làm thế nào để có được giá trị của một biến session bên trong phương thức tĩnh trong C#?Làm thế nào tôi có thể nhận được giá trị của một biến phiên trong một phương thức tĩnh?
protected void Page_Load(object sender, EventArgs e)
{
Session["UserName"] = "Pandiya";
}
[WebMethod]
public static string GetName()
{
string s = Session["UserName"].ToString();
return s;
}
Khi tôi biên dịch này, tôi nhận được lỗi:
An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Session.get'`
Bất kỳ đề nghị hay bất kỳ thay thế?
sử dụng HttpContext.Current như thế này: HttpContext.Current.Session [ "UserName"] ToString();. –