public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id; if (int.TryParse(context.Request.Form["ID"], out id)) { UserInfo userInfo = new UserInfo(); userInfo.ID = id; userInfo.UserName = context.Request.Form["txtUserName"]; userInfo.UserPass = context.Request.Form["passUserPass"]; userInfo.Email = context.Request.Form["txtEmail"]; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); if (userInfoService.Update(userInfo)) { context.Response.Redirect("UserInfoList.ashx"); } else { context.Response.Redirect("Error.html"); } } else { context.Response.Write("更新参数错误"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; //UserInfo userInfo = new UserInfo(); //userInfo.UserName = context.Request.Form["UserName"]; //userInfo.UserPass = context.Request.Form["UserPass"]; //userInfo.RegTime = Convert.ToDateTime(context.Request.Form["RegTime"]); //userInfo.Email = context.Request.Form["Email"]; //userInfo.ID = Convert.ToInt32(context.Request.Form["txtID"]); int id = Convert.ToInt32(context.Request.Form["txtID"]); BLL.UserInfoService userInfoService = new BLL.UserInfoService(); UserInfo userInfo = userInfoService.GetModel(id); userInfo.UserName = context.Request.Form["UserName"]; userInfo.UserPass = context.Request.Form["UserPass"]; if (userInfoService.UpdateEntity(userInfo)) { context.Response.Redirect("UserInfoList.ashx"); } else { context.Response.Write("修改失败"); } }
protected void Page_Load(object sender, EventArgs e) { //如果使用runat="server",则可以使用string.IsNullOrEmpty(Request.Form["isPostBack"])判断是否为post //IsPostBack:如果是post则属性值为false,如果是get则属性值为true //IsPostBack:是根据__VIEWSTATE隐藏域进行判断的,如果是post请求,那么隐藏域的值会提交到服务端 //使用runat="server"后,aspx中的默认form是一个控件,__VIEWSTATE中将记录状态保持的值。也可以不使用,自己写一个隐藏域进行校验如下: if (Context.Request.Form["IsPostBack"] != null) { string userName = Context.Request.Form["txtUserName"]; string userPass = Context.Request.Form["PassUserPass"]; string email = Context.Request.Form["txtEmail"]; UserInfo userInfo = new UserInfo(); userInfo.UserName = userName; userInfo.UserPass = userPass; userInfo.Email = email; userInfo.RegTime = DateTime.Now; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); if (userInfoService.Create(userInfo)) { Context.Response.Redirect("UserInfoWebForm.aspx"); } else { Context.Response.Redirect("/Error.html"); } } }
public ActionResult CheckLogin() { string validateCode = Session["validateCode"] == null ? string.Empty : Session["validateCode"].ToString(); if (string.IsNullOrEmpty(validateCode)) { return(Content("no:验证码错误!")); } Session["validateCode"] = null; string requestCode = Request["vCode"]; if (!requestCode.Equals(validateCode, StringComparison.InvariantCultureIgnoreCase)) { return(Content("no:验证码错误!!")); } string userName = Request["LoginCode"]; string userPwd = Request["LoginPwd"]; BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); T_UserInfo userInfo = UserInfoService.GetUserInfoModel(userName, userPwd); if (userInfo != null) { return(Content("ok:登录成功!!")); } else { return(Content("no:用户名密码错误")); } }
/// <summary> /// 通过检查cookie信息 来自动登录 /// </summary> protected void CheckCookieInfo() { if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null) { string userName = Request.Cookies["cp1"].Value; string userPwd = Request.Cookies["cp2"].Value; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); UserInfo userInfo = userInfoService.GetUserInfo(userName); if (userInfo != null) { //注意:在添加用户或注册用户时一定要将用户输入的密码加密以后在存储到数据库中。 string localPwd = WebCommon.GetMd5(WebCommon.GetMd5(userInfo.UserPass)); if (localPwd == userPwd) { Session["userInfo"] = userInfo; Response.Redirect("UserInfoList.aspx"); } } else { //数据库 数据别人盗取了。 // cookie当中数据如果错误了 cookie中的数据 清空 Response.Cookies["cp1"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["cp2"].Expires = DateTime.Now.AddDays(-1); } } else { //这里就直接出现登陆页面 不用其他的处理 } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id; if (int.TryParse(context.Request["txtEditUserID"], out id)) { Model.UserInfo userInfo = new Model.UserInfo(); userInfo.ID = id; userInfo.UserName = context.Request["txtEditUserName"]; userInfo.UserPass = context.Request["txtEditUserPass"]; userInfo.Email = context.Request["txtEditEmail"]; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); if (userInfoService.Update(userInfo)) { context.Response.Write("ok"); } else { context.Response.Write("no"); } } else { context.Response.Write("no"); } }
protected void Page_Load(object sender, EventArgs e) { int pageSize = 10; int pageIndex; if (!int.TryParse(Context.Request.QueryString["pageIndex"], out pageIndex)) { pageIndex = 1; } BLL.UserInfoService userInfoServer = new BLL.UserInfoService(); //对当前的页码范围进行判断 int pageCount = userInfoServer.GetPageCount(pageSize); pageIndex = pageIndex < 1 ? 1 : pageIndex; pageIndex = pageIndex > pageCount ? pageCount : pageIndex; PageIndex = pageIndex; PageCount = pageCount; List <UserInfo> list = userInfoServer.GetList(pageIndex, pageSize); StringBuilder sb = new StringBuilder(); foreach (UserInfo item in list) { sb.AppendFormat("<li><span>{0}</span><a href='' target='_blank'>{1}</a></li>", item.RegTime.ToShortDateString(), item.UserName); strHtml = sb.ToString(); } }
public string LoadUserInfoList() { IBLL.IUserInfoService userInfoService = new BLL.UserInfoService(); List <Model.UserInfo> list = userInfoService.LoadEntities(u => true).ToList(); return("序列化的数据"); }
protected void Page_Load(object sender, EventArgs e) { int pageSize = 5; int pageIndex; if (!int.TryParse(Request.QueryString["pageIndex"], out pageIndex)) { pageIndex = 1; } BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); int pagecount = UserInfoService.GetPageCount(pageSize);//获取总页数 PageCount = pagecount; //对当前页码值范围进行判断 pageIndex = pageIndex < 1 ? 1 : pageIndex; pageIndex = pageIndex > pagecount ? pagecount : pageIndex; PageIndex = pageIndex; List <UserInfo> list = UserInfoService.GetPageList(pageIndex, pageSize);//获取分页数据 StringBuilder sb = new StringBuilder(); foreach (UserInfo userInfo in list) { sb.AppendFormat("<li><span>{0}</span><a href='#' target='_blank'>{1}</a></li>", userInfo.RegTime.ToShortDateString(), userInfo.UserName); } StrHtml = sb.ToString(); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int pageIndex; if (!int.TryParse(context.Request["pageIndex"], out pageIndex)) { pageIndex = 1; } int pageSize = 5; BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); int pageCount = UserInfoService.GetPageCount(pageSize);//获取总页数. //判断当前页码值的取值范围。 pageIndex = pageIndex < 1 ? 1 : pageIndex; pageIndex = pageIndex > pageCount?pageCount:pageIndex; //获取分页数据 List <UserInfo> list = UserInfoService.GetPageList(pageIndex, pageSize); //获取页码条。 string pageBar = Common.PageBarHelper.GetPagaBar(pageIndex, pageCount); System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); string str = js.Serialize(new { UList = list, MyPageBar = pageBar });//将数据序列化成JSON字符串。匿名类。 context.Response.Write(str); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; int id; if (int.TryParse(context.Request.QueryString["uid"], out id)) { BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); UserInfo userInfo = UserInfoService.GetUserInfo(id);//获取用户的信息. if (userInfo != null) { string filePath = context.Request.MapPath("Detail.html"); string fileContent = File.ReadAllText(filePath); fileContent = fileContent.Replace("$name", userInfo.UserName).Replace("$pwd", userInfo.UserPass); context.Response.Write(fileContent); } else { context.Response.Redirect("Error.html"); } } else { context.Response.Write("参数错误!!"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; int id; if (int.TryParse(context.Request.QueryString["id"], out id)) { BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); UserInfo userInfo = UserInfoService.GetUserInfo(id); if (userInfo != null) { //读取模板文件,替换表单中的占位符. string filePath = context.Request.MapPath("ShowEditUser.html"); string fileContent = File.ReadAllText(filePath); fileContent = fileContent.Replace("$name", userInfo.UserName).Replace("$pwd", userInfo.UserPass).Replace("$mail", userInfo.Email).Replace("$Id", userInfo.Id.ToString()); context.Response.Write(fileContent); } else { context.Response.Write("查无此人!!"); } } else { context.Response.Write("参数错误!!"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int pageIndex; if (!int.TryParse(context.Request["pageIndex"], out pageIndex)) { pageIndex = 1; } int pageSize = 10; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); int pageCount = userInfoService.GetPageCount(pageSize); //判断当前页码值得取值范围 pageIndex = pageIndex < 1 ? 1 : pageIndex; pageIndex = pageIndex > pageCount ? pageCount : pageIndex; List <Model.UserInfo> list = userInfoService.GetList(pageIndex, pageSize); string pagebar = Common.PagebarHelper.GetPagebar(pageIndex, pageCount); System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); //序列化和反序列化的类 string str = js.Serialize(new { UList = list, MyPageBar = pagebar }); //将数据序列化成json字符串。匿名类 context.Response.Write(str); }
protected void CheckUserInfo() { //获取用户输入的用户名和密码. string userName = Request.Form["txtName"]; UserName = userName; string userPwd = Request.Form["txtPwd"]; //校验用户名密码. BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); string msg = string.Empty; UserInfo userInfo = null; //判断用户名与密码 if (UserInfoService.ValidateUserInfo(userName, userPwd, out msg, out userInfo)) { //判断用户是否选择了“自动登录” if (!string.IsNullOrEmpty(Request.Form["autoLogin"]))//页面上如果有多个复选框时,只能将选中复选框的的值提交到服务端。 { HttpCookie cookie1 = new HttpCookie("cp1", userName); HttpCookie cookie2 = new HttpCookie("cp2", Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(userPwd))); cookie1.Expires = DateTime.Now.AddDays(7); cookie2.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(cookie1); Response.Cookies.Add(cookie2); } Session["userInfo"] = userInfo; Response.Redirect("UserInfoList.aspx"); } else { Msg = msg; } }
public string LoadUserInfoList() { IBLL.IUserInfoService UserInfoService = new BLL.UserInfoService(); List <Model.UserInfo> list = UserInfoService.LoadEntities(u => true).ToList(); return(Common.SerializeHelper.SerializeToString(list)); //SOA:面向服务。 }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id = Convert.ToInt32(context.Request["id"]); BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); UserInfo userInfo = UserInfoService.GetUserInfo(id); System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); context.Response.Write(js.Serialize(userInfo)); }
protected void Page_Load(object sender, EventArgs e) { int id = Convert.ToInt32(Request["id"]); BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); UserInfo userInfo = UserInfoService.GetUserInfo(id); List <UserInfo> list = new List <UserInfo>(); list.Add(userInfo); this.DetailsView1.DataSource = list; this.DetailsView1.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { int id = int.Parse(Request["id"]); BLL.UserInfoService userInfoService = new BLL.UserInfoService(); Model.UserInfo userInfo = userInfoService.GetList(id); List <Model.UserInfo> list = new List <Model.UserInfo>(); list.Add(userInfo); this.DetailsView1.DataSource = list; this.DetailsView1.DataBind(); }
/// <summary> /// 页面加载完成后。load事件 类似WinForm里的Form_Load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { BLL.UserInfoService userInfoService = new BLL.UserInfoService(); List <Model.UserInfo> userlist = userInfoService.GetList(); List = userlist; //StringBuilder sb = new StringBuilder(); //foreach (Model.UserInfo userInfo in userlist) //{ // sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a href='UserDetailWebForm.aspx?id={0}'>Detail</a></td><td><a href='javascript:void(0)' onclick= rowDelete(\"{1}\",\"{0}\")>Delete</a></td><td><a href='UpdateUserDetail.ashx?id={0}'>Update</a></td></tr>", userInfo.ID, userInfo.UserName, userInfo.UserPass, userInfo.Email, userInfo.RegTime); //} //StrHtml = sb.ToString(); }
/// <summary> /// 页面加载完成以后。Load事件 Form_Load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); List <UserInfo> list = UserInfoService.GetList(); UserList = list; //StringBuilder sb = new StringBuilder(); //foreach (UserInfo userInfo in list) //{ // sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>",userInfo.Id,userInfo.UserName,userInfo.UserPass,userInfo.Email,userInfo.RegTime.ToShortDateString()); //} //StrHtml = sb.ToString(); }
public void GetUserDetailInfo(string ID) { int id; if (int.TryParse(ID, out id)) { BLL.UserInfoService userInfoService = new BLL.UserInfoService(); userInfo = userInfoService.GetList(id); } else { Context.Response.Redirect("/Error.htm"); } }
protected void CheckUserInfo() { //session存储在内存中 //不要将过大的数据复制给session //session要判断是否为空 string userName = Request.Form["txtName"]; UserName = userName; string userPwd = Request.Form["txtPwd"]; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); string msg = string.Empty; UserInfo userInfo = null; bool isLogin = userInfoService.ValidateUserInfo(userName, userPwd, out msg, out userInfo); //判断用户名密码是否正确 if (isLogin) { //页面上如果有多个复选框时,只能将选中复选框的的值提交到服务端。 if (!string.IsNullOrEmpty(Request.Form["autoLogin"])) { string pwd = ""; //可以一种算法加密好几次 别人破解不了的那种 //第一次登陆的时候 加密之后保存到 cookie当中 // 第一次加载页面的 根据cookie的值来判断一下 pwd = WebCommon.GetMd5(WebCommon.GetMd5(userPwd)); HttpCookie cookie1 = new HttpCookie("cp1", userName); HttpCookie cookie2 = new HttpCookie("cp2", pwd); cookie1.Expires = DateTime.Now.AddDays(7); cookie2.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(cookie1); Response.Cookies.Add(cookie2); } //Session过期了之后 就访问不打的 //是滑动过期时间。再次访问的时候 时间 会往后延长 //赋值几个页面 不要把所有的页面全部都复制过去 Session["userInfo"] = userInfo; Response.Redirect("UserInfoList.aspx"); } else { Msg = msg; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; int id; if (int.TryParse(context.Request.QueryString["id"], out id)) { BLL.UserInfoService userInfoService = new BLL.UserInfoService(); UserInfo userInfo = userInfoService.GetModel(id); string filePath = context.Request.MapPath("ShowDetail.html"); string fileContent = File.ReadAllText(filePath); fileContent = fileContent.Replace("$name", userInfo.UserName.ToString()).Replace("$pwd", userInfo.UserPass.ToString()); context.Response.Write(fileContent); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string userName = context.Request["userName"]; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); if (userInfoService.GetList(userName) != null) { context.Response.Write("此用户名已存在"); } else { context.Response.Write("此用户名可用"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id = Convert.ToInt32(context.Request["id"]); BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); if (UserInfoService.DeleteUserInfo(id)) { context.Response.Write("ok"); } else { context.Response.Write("no"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id; if (int.TryParse(context.Request["id"], out id)) { BLL.UserInfoService userInfoService = new BLL.UserInfoService(); Model.UserInfo userInfo = new Model.UserInfo(); userInfo = userInfoService.GetList(id); 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"; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); int id; if (int.TryParse(context.Request["id"], out id)) { Model.UserInfo userInfo = new Model.UserInfo(); userInfo = userInfoService.GetList(id); } else { context.Response.Write("no"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; BLL.UserInfoService userInfoService = new BLL.UserInfoService(); List <UserInfo> list = userInfoService.GetList(); StringBuilder sb = new StringBuilder(); foreach (UserInfo userInfo in list) { sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a href='ShowUserDetail.ashx?id={0}'>Detail</a></td><td><a href='javascript:void(0)' onclick= rowDelete(\"{1}\",\"{0}\")>Delete</a></td><td><a href='UpdateUserDetail.ashx?id={0}'>Update</a></td></tr>", userInfo.ID, userInfo.UserName, userInfo.UserPass, userInfo.Email, userInfo.RegTime); } string filePath = context.Request.MapPath("UserInfoList.html"); string fileContent = File.ReadAllText(filePath); fileContent = fileContent.Replace("@tboby", sb.ToString()); context.Response.Write(fileContent); }
protected void Page_Load(object sender, EventArgs e) { if (Cache["userInfoList"] == null) { BLL.UserInfoService userInfoService = new BLL.UserInfoService(); List <Model.UserInfo> list = userInfoService.GetList(); //Cache["userInfoList"] = list; Cache.Insert("userInfoList", list, null, DateTime.Now.AddSeconds(10), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, RemoveCache); Response.Write("数据来自数据库。"); //Cache.Remove("userInfoList"); } else { List <Model.UserInfo> list = (List <Model.UserInfo>)Cache["userInfoList"]; Response.Write("数据来自缓存"); } }
protected void InsertUserInfo() { Model.UserInfo UserInfo = new Model.UserInfo(); UserInfo.UserName = Request.Form["txtName"]; UserInfo.UserPass = Request.Form["txtPwd"]; UserInfo.Email = Request.Form["txtMail"]; UserInfo.RegTime = DateTime.Now; BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); if (UserInfoService.AddUserInfo(UserInfo)) { Response.Redirect("UserInfoList.aspx"); } else { Response.Redirect("/Error.html"); } }