将asp.net会话变量传递给通过jquery调用的Web方法

Chu*_*ill 1 asp.net-ajax

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);
    }
});
Run Code Online (Sandbox Code Playgroud)

lang在我的页面上可以作为Session ["Lang"].如何访问并将其发送到Web方法?

Dar*_*rov 7

您可以直接访问页面方法内的会话:

[WebMethod(EnableSession = true)]
public static string ShowMain()
{
    var lang = HttpContext.Current.Session["Lang"];  
    return "foo";
}
Run Code Online (Sandbox Code Playgroud)