Пример #1
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.ContentType = ResponseContentType;

                //获取上传文件集合
                HttpFileCollection files = GetHttpPostedFile(context);
                if (files == null)
                {
                    throw new FileNotFoundException("UpdateFile Not Found! HttpPostedFile Is NULL!");
                }

                //获取临时目录
                string uploadPath   = "/" + MvcApplication.UploadFolder + "/Temp/" + DateTime.Now.ToString("yyyyMMdd") + "/";;
                string uploadPathMP = context.Server.MapPath(uploadPath);
                if (!Directory.Exists(uploadPathMP))
                {
                    //不存在则自动创建文件夹
                    Directory.CreateDirectory(uploadPathMP);
                }
                string fileNames = string.Empty;

                string ext;
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile postedFile = files[i];

                    ext = Path.GetExtension(postedFile.FileName).ToLower();
                    if (!AllowFileExt.Contains(ext))
                    {
                        LogHelp.AddInvadeLog("Handlers-UploadMultipleFileHandler", context.Request);
                        return;
                    }

                    //文件重命名
                    string reName = DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + ext;
                    postedFile.SaveAs(uploadPathMP + reName);
                    string thumName = "T300X400_" + reName;
                    //临时保存文件
                    ImageTools.MakeThumbnail(uploadPathMP + reName, uploadPathMP + thumName, 300, 400, MakeThumbnailMode.HW);
                    fileNames += "|" + thumName;
                }
                //json方式输出成功信息 和 保存路径 , 文件名
                JsonObject json = new JsonObject();
                json.Put("success", true);                   //成功
                json.Put("path", uploadPath + "{0}");        //临时保存路径
                json.Put("names", fileNames.TrimStart('|')); //文件名 | 分割
                context.Response.Write(json.ToString());     //输出json数据
            }
            catch (Exception ex)
            {
                Model.SysManage.ErrorLog model = new Model.SysManage.ErrorLog();
                model.Loginfo    = ex.Message;
                model.StackTrace = ex.ToString();
                model.Url        = context.Request.Url.AbsoluteUri;
                BLL.SysManage.ErrorLog.Add(model);
                throw;
            }
        }
Пример #2
0
        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = ResponseContentType;

            HttpPostedFile file = GetHttpPostedFile(context);

            if (file == null)
            {
                throw new FileNotFoundException("UpdateFile Not Found! HttpPostedFile Is NULL!");
            }
            if (file.FileName.Length < 1)
            {
                return;
            }

            if (!AllowFileExt.Contains(Path.GetExtension(file.FileName).ToLower()))
            {
                LogHelp.AddInvadeLog("Handlers-UploadHandlerBase", context.Request);
                return;
            }

            //文件重命名
            string fileName = GenerateFileName(file);

            try
            {
                if (IsLocalSave)
                {
                    string uploadPath = GetUploadPath(context);
                    if (!Directory.Exists(uploadPath))
                    {
                        //不存在则自动创建文件夹
                        Directory.CreateDirectory(uploadPath);
                    }
                    //保存文件
                    SaveAs(uploadPath, fileName, file);
                }
                else
                {
                    int    filelength = file.ContentLength;
                    byte[] buffer     = new byte[filelength];
                    file.InputStream.Read(buffer, 0, filelength);
#pragma warning disable CS0219 // 变量“ImageUrl”已被赋值,但从未使用过它的值
                    string ImageUrl = "";
#pragma warning restore CS0219 // 变量“ImageUrl”已被赋值,但从未使用过它的值
                }
                //调用子类实现
                ProcessSub(context, UploadTempFolder, fileName);
            }
            catch (Exception ex)
            {
                Model.SysManage.ErrorLog model = new Model.SysManage.ErrorLog();
                model.Loginfo    = ex.Message;
                model.StackTrace = ex.ToString();
                model.Url        = context.Request.Url.AbsoluteUri;
                ColoPay.BLL.SysManage.ErrorLog.Add(model);
                throw;
            }
        }
Пример #3
0
        public ActionResult VerifyPassword(FormCollection collection)
        {
            if (!String.IsNullOrWhiteSpace(collection["Email"]) && !String.IsNullOrWhiteSpace(collection["NewPwd"]))
            {
                string secretKey = collection["SecretKey"];
                string username  = collection["Email"].Trim();
                string password  = collection["NewPwd"];

                YSWL.MALL.BLL.SysManage.VerifyMail bll = new YSWL.MALL.BLL.SysManage.VerifyMail();

                YSWL.MALL.Model.SysManage.VerifyMail model = bll.GetModel(secretKey);
                if (model == null || !model.ValidityType.HasValue || model.ValidityType.Value != 1 ||
                    model.UserName != username)
                {
                    //非法修改密码
                    LogHelp.AddInvadeLog("Areas.SNS.Controllers-HttpPost-VerifyPassword", System.Web.HttpContext.Current.Request);
                    return(HttpNotFound());
                }

                User currentUser = new User(username);
                if (String.IsNullOrWhiteSpace(password))
                {
                    ModelState.AddModelError("Error", "该用户不存在!");
                    return(View());
                }
                currentUser.Password = AccountsPrincipal.EncryptPassword(YSWL.Common.PageValidate.InputText(password, 30));
                if (!currentUser.Update())
                {
                    ModelState.AddModelError("Error", "密码重置失败,请检查输入的信息是否正确或者联系管理员!");
                    return(View());
                }
                else
                {
                    AccountsPrincipal newUser = AccountsPrincipal.ValidateLogin(username, password);
                    FormsAuthentication.SetAuthCookie(username, false);
                    Session[Globals.SESSIONKEY_USER] = currentUser;
                    Session["Style"] = currentUser.Style;
                    YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                    pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                    BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");
                    if (Session["returnPage"] != null)
                    {
                        string returnpage = Session["returnPage"].ToString();
                        Session["returnPage"] = null;
                        return(Redirect(returnpage));
                    }
                    else
                    {
                        return(RedirectToAction("Posts", "Profile"));
                    }
                }
            }
            return(View());
        }
Пример #4
0
        public override void ProcessRequest()
        {
            try
            {
                base.ProcessRequest();
            }
            catch (JsonRpcException ex)
            {
                if (HttpContext.Current.IsDebuggingEnabled)
                {
                    throw;
                }

                LogHelp.AddInvadeLog(ex.Message, System.Web.HttpContext.Current.Request);
                Response.Clear();
                Response.StatusCode = 404;
                Response.Status     = "404 Not Found";
                Response.End();
            }
        }