在客户端检查表单身份验证

时间:2015-02-02 13:32:07

标签: javascript jquery asp.net

我在ASP.NET网站上使用表单身份验证,我需要检查如果用户在客户端进行回调之前已经过身份验证,我该如何使用JavaScript / jQuery进行验证?

1 个答案:

答案 0 :(得分:-1)

您需要定义一个web方法来检查会话状态,然后使用.ajax查询该方法。

[WebMethod]
public static string GetSession(string Skey)
{
     return Session[Skey];
}

[WebMethod]
public static string SetSession(string key, string Svalue)
{
     Session[key] = Svaluee;
}

jQuery的:

$.ajax({
            type: "POST",
            url: "website.aspx/GetSessionValue",
            data: '{ key: "CurrentSessionKey" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data) {

                  console.log("The Session value is " + data);
            }
});

更新

阅读错误的问题。希望这可以帮助。

相关问题