jcv*_*gan 10 asp.net session jquery webforms
我通过WebMethod将变量传递给会话
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public static bool lookEventQ(int eventuid)
{
HttpContext.Current.Session["Q_EVENT_ID"] = eventuid;
return true;
}
Run Code Online (Sandbox Code Playgroud)
使用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
}
});
Run Code Online (Sandbox Code Playgroud)
但是,在另一个页面上,尝试访问此会话变量:
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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当访问时,会话是空的
| 归档时间: |
|
| 查看次数: |
784 次 |
| 最近记录: |