开发者

Pass asp.net session variable to a web method called via jquery

开发者 https://www.devze.com 2023-01-18 01:59 出处:网络
function getMainContent(ID, num, lang){ $.ajax({ type: \"POST\", url: \"WebMethods.aspx/showMain\", data: \'{AID: \"\' + articleID+ \'\", ANum: \"\' +num + \'\"}\',
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

精彩评论

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