【发布时间】:2016-08-06 10:10:09
【问题描述】:
我通过 WebMethod 将变量传递给会话
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public static bool lookEventQ(int eventuid)
{
HttpContext.Current.Session["Q_EVENT_ID"] = eventuid;
return true;
}
使用 jQuery 调用它:
$.ajax({
url: "<%= ResolveUrl("~/public-conference.aspx")%>/lookEventQ?eventuid=" + event,
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
//DO STUFF
}
});
然后,在另一个页面上,尝试访问这个会话变量:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (int.TryParse(Request.Form.Get(CONST_postKey), out eventID))
{
if(eventID == int.Parse(HttpContext.Current.Session["Q_EVENT_ID"])){
//Do other stuff
}
}
}
}
但是当tring访问时,Session是空的
【问题讨论】:
-
你的webmethod调用成功了吗?
-
是的。方法总是被前端调用
标签: jquery asp.net session webforms