protected void Page_Load(object sender, EventArgs e) { #region 个人信息 if (Request.Cookies["VideoNetcookieLogin"] != null) { modelUsers = bllUsers.GetModel(Request.Cookies["VideoNetcookieLogin"]["UserAccount"]); modelPlayRight = bllPlayRight.GetModel(modelUsers.UserAccount); Account = modelUsers.UserAccount; Name = modelUsers.UserName; ExpireTime = modelPlayRight.ExpireTime; WatchRecord = modelPlayRight.WatchRecord; HeadPortrait = modelPlayRight.HeadPortrait; hidAccount.Value = modelUsers.UserAccount; hidImg.Value = modelPlayRight.HeadPortrait; return; } if (Session["userInfo"] != null) { modelUsers = (Model.Users)Session["userInfo"]; modelPlayRight = bllPlayRight.GetModel(modelUsers.UserAccount); Account = modelUsers.UserAccount; Name = modelUsers.UserName; ExpireTime = modelPlayRight.ExpireTime; WatchRecord = modelPlayRight.WatchRecord; HeadPortrait = modelPlayRight.HeadPortrait; hidImg.Value = modelPlayRight.HeadPortrait; hidAccount.Value = modelUsers.UserAccount; return; } Name = "未登录"; Account = "未登录"; ExpireTime = DateTime.Now; HeadPortrait = "b614d3bf0d897dd651f1b937b957ac8a.jpg"; WatchRecord = null; hidAccount.Value = null; #endregion }
protected void Button1_Click(object sender, EventArgs e) { //判断用户是否登录 if (!string.IsNullOrEmpty(hidAccount.Value) && hidAccount.Value != "未登录") { string newFile = ""; string fileExt = ""; HttpPostedFile file = Request.Files[0]; //判断上传图片的时候img里面有没有图片如果有 if (string.IsNullOrEmpty(hidImg.Value)) { //首次上传图片不需要删除原有的 if (file.ContentLength > 0) { string fileName = Path.GetFileName(file.FileName); fileExt = Path.GetExtension(fileName); string[] suffix = { ".jpg", ".png" }; for (int i = 0; i < suffix.Length; i++) { if (fileExt == suffix[i]) { //对上传文件重名命 newFile = Guid.NewGuid().ToString(); //将上传的文件放在不同的目录下 string dir = "/HeadPortraitImages/" + newFile; string fullDir = dir + fileExt; //文件存放的完整路劲 file.SaveAs(Request.MapPath(fullDir)); //将上传的文件保存在到HeadPortraitImages文件里 } } } } else { if (file.ContentLength > 0) { //如果有则删除原有的 File.Delete(Server.MapPath("/HeadPortraitImages/" + hidImg.Value)); string fileName = Path.GetFileName(file.FileName); fileExt = Path.GetExtension(fileName); string[] suffix = { ".jpg", ".png" }; for (int i = 0; i < suffix.Length; i++) { if (fileExt == suffix[i]) { //对上传文件重名命 newFile = Guid.NewGuid().ToString(); //将上传的文件放在不同的目录下 string dir = "/HeadPortraitImages/" + newFile; string fullDir = dir + fileExt; //文件存放的完整路劲 hidImg.Value = fullDir; file.SaveAs(Request.MapPath(fullDir)); //将上传的文件保存在到HeadPortraitImages文件里 } } } else { common.MsgTrans("请选择头像", this); return; } } modelPlayRight = bllPlayRight.GetModel(hidAccount.Value);//得到用户的播放信息 modelPlayRight.HeadPortrait = newFile + fileExt; bllPlayRight.Update(modelPlayRight); Response.Redirect("PersonalMessage.aspx"); } else { common.MsgTrans("请先登录了才能上传头像哦", this); } }
public void ProcessRequest(HttpContext context) { BLL.Users bllUser = new BLL.Users(); Model.Users modelUsers = new Model.Users(); string UserAccount = context.Request["UserAccount"]; string UserPassWord = common.MD5(common.MD5(common.SQLFilter(context.Request["UserPassWord"]))); action = context.Request["action"]; switch (action) { case "xxx": //此处没有在ajax中发送数据如需要用请在js中调用 int UserChckbox = Convert.ToInt32(context.Request["checkboxid"]); Code = context.Session["vCode"] != null ? context.Session["vCode"].ToString() : ""; modelUsers = bllUser.GetModel(UserAccount); if (Code == common.SQLFilter(context.Request["Code"])) { if (bllUser.CheckUserInfo(UserAccount, UserPassWord, out modelUsers)) { if (modelUsers.UsersState == 1) { context.Session["userInfo"] = modelUsers; if (UserChckbox == 1) { //将登录的用户存在cookie中 cookie.Expires = DateTime.Now.AddDays(7); cookie.Values.Add("UserAccount", UserAccount); cookie.Values.Add("UserPassWord", UserPassWord); context.Response.AppendCookie(cookie); } context.Response.Write("/HomePage.aspx"); } else { context.Response.Write("no:用户被锁定和用户异常请联系站长QQ1300646029发送账号"); } } else { context.Response.Write("no:没有此用户和以注销请联系站长QQ1300646029发送我要账号附带邮箱"); } } else { context.Response.Write("no:请先输入正确的验证码和请点击验证码刷新验证码"); } break; case "APP": try { if (bllUser.CheckUserInfo(UserAccount, UserPassWord, out modelUsers)) { if (modelUsers.UsersState == 1) { Model.PlayRight modelPlayRight = new Model.PlayRight(); BLL.PlayRight bllPlayRight = new BLL.PlayRight(); modelPlayRight = bllPlayRight.GetModel(modelUsers.UserAccount); context.Response.Write(fastJSON.JSON.Instance.ToJSON(modelUsers.UserName + "," + modelUsers.UserAccount + "," + modelPlayRight.HeadPortrait)); } else { context.Response.Write("0"); } } } catch (Exception ex) { context.Response.Write("0"); } break; case "NetName": try { BLL.Config bllConfig = new BLL.Config(); context.Response.Write(fastJSON.JSON.Instance.ToJSON(bllConfig.ExGetConfigValue("网站名称"))); } catch (Exception ex) { context.Response.Write("0"); } break; default: context.Response.Write("0"); break; } }