开发者

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";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜