Pass asp.net session variable to a web method called via jquery
function getMainContent(ID, num, lang){
$.ajax({
type: "POST",
url: "WebMethods.aspx/showMain",
data: '{AID: "' + articleID+ '", ANum: "' +num + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: showSuccess,
failure: function(response) {
alert(response);
}
});
lang is available on my page as Session["Lang"]. How do I acces开发者_开发知识库s and send it to the web method?
You can directly access the session inside the page method:
[WebMethod(EnableSession = true)]
public static string ShowMain()
{
var lang = HttpContext.Current.Session["Lang"];
return "foo";
}
精彩评论