public ActionResult Add() { var id = Request.Form["mhid"]; var sort = Request.Form["sort"]; // 章节ID var name = Request.Form["name"]; var gid = 0; Tab_User u = null; HttpCookie authCookie = Request.Cookies["a"]; // 获取cookie if (authCookie != null) { try { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // 解密 var user = SerializeHelper.FromJson <Tab_User>(ticket.UserData); u = _us.GetUser(user.F_Name, user.F_Password); if (u != null) { } else { return(RedirectToAction("SignOut", "Home")); } } catch (Exception ex) { return(RedirectToAction("SignOut", "Home")); } } var gzh = _gzhs.GetGZH(u.F_Id); if (gzh != null) { gid = gzh.F_Id; } if (gid == 0) { // IE浏览器对非ajax请求Content-Type:是json的不友好所以使用View而非Json return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "账号没有关联公众号" })); } int mhid = 0; if (id == null || !int.TryParse(id, out mhid) || mhid == 0) { return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "漫画ID无效" })); } int zjid = 0; if (sort == null || !int.TryParse(sort, out zjid) || zjid == 0) { return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "章节ID无效" })); } if (name == null || name.Length > 50) { return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "章节名称长度必须小于50字符" })); } var img = ""; if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0 && new string[] { ".gif", ".jpeg", ".jpg", ".png" }.Contains(System.IO.Path.GetExtension(Request.Files[0].FileName.ToLower()))) { var key = QN.MHimg(gid, mhid); var token = QN.GetUploadToken(QN.BUCKET, key); FormUploader fu = new FormUploader(); HttpResult result = fu.UploadStream(Request.Files[0].InputStream, key, token); if (result.Code == 200) { img = key; } } else { return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "请为章节内容添加图片" })); } Tab_MHImg m = new Tab_MHImg(); m.F_Name = name; m.F_Img = img != "" ? img : null; m.F_MHId = mhid; m.F_Sort = zjid; m.F_UserId = u.F_Id; var i = _mhs.AddImg(m); if (i == 1) { return(View(new DWZJson() { statusCode = (int)DWZStatusCode.OK, message = "成功" })); } else if (i == 2) { return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "章节重复" })); } else { return(View(new DWZJson() { statusCode = (int)DWZStatusCode.ERROR, message = "失败" })); } }