-1

我在登录页面中使用 jquery,在这里我需要捕获电子邮件 ID 和密码并存储在会话中以在其他页面中使用。如何使用 jquery 存储在会话中输入的值。

我的代码

    $.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        url: "home.aspx/ValidateUser",
        data: (JSON.stringify({ emailid: strEmail, password: strPassword })),
        success: function (responseText) {

            var IsUserExists = responseText.d

            switch (IsUserExists) {
                case "0":
                    alert("Your are not registered user. Please register yours before login.");
                    break;
                case "1":
                    LoginToUserProfile(strEmail, strPassword);
                    break;
                case "2":
                    alert("Please activate your account from you registered email and then try to login.");
                    break;
            }
        },
        error: function (responseText) {
            alert("Error in validation --->" + responseText);
        }
    });  
    return false;

}



function LoginToUserProfile(strEmail, strPassword) {

    $.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        url: "home.aspx/GetUserId",
        data: (JSON.stringify({ emailid: strEmail, password: strPassword })),
        success: function (responseText) {
            var UserId = responseText.d
            window.location = "users/userhomepage.aspx?userid=" + UserId;
        },
        error: function (responseText) {
            alert("Error in LoginToUserProfile --->" + responseText);
        }
    });
    return false;
}

如何从 login.help 我在会话中存储电子邮件 ID 和密码的值

4

1 回答 1

1

您必须将其存储在控制器中,然后在需要使用它的每个页面(在 UI 中)创建一个隐藏字段,其中填充了必要的信息。

在您的 url 中,将值更改为"url: Home/ValidateUser"Home 控制器,您应该定义 ValidateUser 操作。

public ValidateUser(string emailid, string password)
{
  Session["email"] = emailid;
  Session["password"] = password;
}

但是,如果您这样做是为了进行身份验证,请重新考虑使用更常用的解决方案。

于 2012-12-20T20:17:49.440 回答