简体   繁体   English

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

[英]Check Form Authentication in Client-Side

我在ASP.NET网站中使用表单身份验证,我需要检查用户是否已通过身份验证,然后再在客户端进行回调,我该如何使用JavaScript / jQuery?

You need to define a webmethod to check the session status and then have a .ajax query the method. 您需要定义一个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: 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);
            }
});

Update 更新资料

Read the question wrong. 阅读题做错。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM