Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Session object inside a WebMethod (using EnableSession = true) not storing value

I am passing a variable to a session via WebMethod

[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public static bool lookEventQ(int eventuid)
{
    HttpContext.Current.Session["Q_EVENT_ID"] = eventuid;
    return true;
}

Calling it by using 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
                }
            });

But then, on another page, try to access to this session variable:

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
            }
        }
    }
}

But when tring to access, the Session is empty

like image 579
jcvegan Avatar asked Apr 14 '16 17:04

jcvegan


1 Answers

Found the solution. As the asp file doesn't contains a ScriptManager with property EnablePageMethods set to true, the session not maintains.

like image 92
jcvegan Avatar answered Oct 20 '22 01:10

jcvegan