public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; int id; if (int.TryParse(context.Request.QueryString["id"], out id)) { Bll.UserInfoBll userInfoBll = new Bll.UserInfoBll(); UserInfo userInfo = userInfoBll.GetUserInfo(id); if (userInfo != null) { string filePath = context.Request.MapPath("ShowEdit.html"); string fileContent = File.ReadAllText(filePath); fileContent = fileContent.Replace("$name", userInfo.UserName).Replace("$pwd", userInfo.UserPwd).Replace("$email", userInfo.Email).Replace("$id", userInfo.UserId.ToString()); context.Response.Write(fileContent); } else { context.Response.Redirect("查无此人"); } } else { context.Response.Write("参数错误"); } }
private void CheckUserInfo() { string userName = Request.Form["txtName"]; string userPwd = Request.Form["txtPwd"]; Bll.UserInfoBll userInfoBll = new Bll.UserInfoBll(); UserInfo LoginUserInfo = userInfoBll.GetUserInfo(userName); if (LoginUserInfo != null) { if (userPwd == LoginUserInfo.UserPwd) { //判断用户是否选择了自动登录 //页面上有多个复选框时,只能将选中复选框的值提交到服务端 if (!string.IsNullOrEmpty(Request.Form["autoLogin"])) { Response.Cookies["username"].Value = Server.UrlEncode(LoginUserInfo.UserName); Response.Cookies["username"].Expires = DateTime.Now.AddDays(3); Response.Cookies["userpwd"].Value = Common.webCommon.GetMd5String(Common.webCommon.GetMd5String(LoginUserInfo.UserPwd)); Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays(3); } Session["userInfo"] = LoginUserInfo; Response.Redirect("UserInfiList.aspx"); } else { Msg = "用户名或密码错误"; } } else { Msg = "该用户名尚未注册"; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int userId = Convert.ToInt32(context.Request["id"]); Bll.UserInfoBll userInfoBll = new Bll.UserInfoBll(); UserInfo userInfo = userInfoBll.GetUserInfo(userId); //别忘了将数据序列化成json数据 System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); context.Response.Write(js.Serialize(userInfo)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string userName = context.Request["name"]; Bll.UserInfoBll userInfiBll = new Bll.UserInfoBll(); if (userInfiBll.GetUserInfo(userName) != null) { context.Response.Write("用户名已存在"); } else { context.Response.Write("用户名可用"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; int id = Convert.ToInt32(context.Request.Form["txtId"]);//接收隐藏域中的值, Bll.UserInfoBll userInfoBll = new Bll.UserInfoBll(); UserInfo userInfo = userInfoBll.GetUserInfo(id); //通过这个id获取用户信息 userInfo.UserName = context.Request.Form["txtName"]; //通过表单中的信息重新赋值 userInfo.UserPwd = context.Request.Form["txtPwd"]; userInfo.Email = context.Request.Form["txtMail"]; if (userInfoBll.EditUserInfo(userInfo)) { context.Response.Redirect("UserInfoList.ashx"); } else { context.Response.Redirect("Error.html"); } }
/// <summary> /// 展示要修改的用户的信息 /// </summary> private void ShowEditUserInfo() { int id; if (int.TryParse(Context.Request.QueryString["id"], out id)) { UserInfo userinfo = userInfoBll.GetUserInfo(id); if (userinfo != null) { EditUserInfo = userinfo; } else { Response.Redirect("Error.html"); } } else { Response.Redirect("Error.html"); } }
private void CheckCookieInfo() { if (Request.Cookies["username"] != null && Request.Cookies["userpwd"] != null) { //自己在测试的时候,发现如果Cookie中存的是中文,这里接收到Cookie来进行查找用户信息,会找不到,而英文则没问题,有待解决 //已解决:Server.UrlEncode()和Server.UrlDecode() 用这两个方法把中文进行编码和解码就行了 string userName = Server.UrlDecode(Request.Cookies["username"].Value); string userPwd = Request.Cookies["userpwd"].Value; Bll.UserInfoBll userInfoBll = new Bll.UserInfoBll(); UserInfo AotoLoginUserInfo = userInfoBll.GetUserInfo(userName); if (AotoLoginUserInfo != null) { if (Common.webCommon.GetMd5String(Common.webCommon.GetMd5String(AotoLoginUserInfo.UserPwd)) == userPwd) { Session["userInfo"] = AotoLoginUserInfo; Response.Redirect("UserInfiList.aspx"); } } //如果拿到的Cookie数据与数据库中用户的用户名和密码不符合,就将该Cookie删掉 Response.Cookies["username"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays(-1); } }