10
Jestem przechodzącą zmienną do sesji poprzez WebMethodUstaw obiekt Session wewnątrz WebMethod (używając EnableSession = true) nie przechowywania wartości
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public static bool lookEventQ(int eventuid)
{
HttpContext.Current.Session["Q_EVENT_ID"] = eventuid;
return true;
}
Wywołanie go za pomocą 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
}
});
ale potem , na innej stronie, spróbuj uzyskać dostęp do tej zmiennej sesji:
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
}
}
}
}
Ale gdy Tring do dostępu, Sessio n jest pusty
jest Twój webmethod zwany pomyślnie? – Mairaj
Tak, jest. Metoda jest zawsze wywoływana przez front-end – jcvegan