Exemplo n.º 1
0
        /// <summary>
        /// 记录当前用户到Cookie
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        public static void AddUserToCookie(string email,string password,bool rememberme)
        {
            UtopiaService utopiaService=new UtopiaService();
            Uto_User user=utopiaService.GetUserByEmail(email);

            HttpCookie cookie=new HttpCookie("authCookie");
            int randomNum = new Random().Next(100);
            cookie.Values["authAdd"] = randomNum.ToString();
            cookie.Values["authCookie"] = Utility.EncodeCookie(user.UserId,randomNum);

            if (rememberme)
                cookie.Expires = DateTime.Now.AddDays(7);

            HttpContext.Current.Response.AppendCookie(cookie);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存图片
        /// </summary>
        /// <param name="file">文件</param>
        /// <param name="AttachmentType">附件类型</param>
        public static void SavePic(HttpPostedFileBase file, string attachmentType, out string attachmentUrl, out long attachmentId)
        {
            string extenseName = file.FileName.Substring(file.FileName.LastIndexOf('.'));
            if (!CheckExtensionName(extenseName))
            {
                attachmentUrl = "0";
                attachmentId = 0;
                return;
            }

            UtopiaService utopiaService = new UtopiaService();

            Uto_Attachment attachment = new Uto_Attachment();
            attachment.UserId = UserContext.CurrentUser.UserId;
            attachment.BelongId = 0;
            attachment.Type = attachmentType;
            attachment.Url = string.Empty;

            //创建附件记录
            utopiaService.AddAttachment(attachment);

            //每100张图片在一个目录
            long i = 100;
            while (true)
            {
                if (attachment.AttachmentId < i)
                    break;
                else
                    i = i + 100;
            }

            string path = HttpContext.Current.Server.MapPath("~/Content/Attachment/" + attachmentType + "/" + i.ToString() + "/");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //获取上传图片的宽与高
            System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
            attachment.Width = img.Width;
            attachment.Height = img.Height;
            //更新附件URL
            attachment.Url = "../../Content/Attachment/" + attachmentType + "/" + i.ToString() + "/" + attachment.AttachmentId.ToString() + extenseName;
            utopiaService.UpdateAttachment(attachment);

            //设置 attachmentUrl attachmentId
            attachmentUrl = attachment.Url;
            attachmentId = attachment.AttachmentId;

            file.SaveAs(path + attachment.AttachmentId.ToString() + extenseName);
        }