使用asp.net中的jquery获取表单值并将其存储在会话中
我在登录页面中使用jquery,这里我需要捕获emailid和密码并存储在会话中,以便在其他页面中使用。如何使用jquery存储会话中输入的值 我的代码使用asp.net中的jquery获取表单值并将其存储在会话中,asp.net,session,jquery,Asp.net,Session,Jquery,我在登录页面中使用jquery,这里我需要捕获emailid和密码并存储在会话中,以便在其他页面中使用。如何使用jquery存储会话中输入的值 我的代码 $.ajax({ type: "POST", async: false, dataType: "json", contentType: "application/json; charset=utf-8", url: "home.aspx/ValidateUs
$.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;
}
如何在登录会话中存储电子邮件id和密码的值。帮助我您必须将其存储在控制器中,然后在需要使用它的每个页面(在UI中)创建一个包含必要信息的隐藏字段 在url中,将值更改为
“url:Home/ValidateUser”
,并在Home controller中定义ValidateUser操作
public ValidateUser(string emailid, string password)
{
Session["email"] = emailid;
Session["password"] = password;
}
但是,如果您这样做是为了进行身份验证,请重新考虑使用更常用的解决方案。我在.cs page webmethod中使用的另一个方法是:如何捕获会话#region ValidateUser[webmethod]public static string ValidateUser(string emailid,string password){user objUser=new user();string strReturn=string.Empty;strReturn=objUser.ValidateUserExists(emailid,密码);return strReturn;}endregion}regionValidateUser@felipeclopes.cs页面[WebMethod]中的我的代码公共静态字符串ValidateUser(字符串emailid,字符串密码){user objUser=new user();string strReturn=string.Empty;strReturn=objUser.ValidateUserExists(emailid,password);return strReturn;}#endregion#region ValidateUser