예제 #1
0
        /// <summary>
        /// 判断用户是否已经登录
        /// Update  2015/11/21  登录采用Cookies+Redis的方式进行
        /// </summary>
        public bool IsUserLogin()
        {
            //通过Cookies获得SessionID
            string sessionID = Utils.GetCookie(DTKeys.COOKIE_USER_INFO_REMEMBER);

            if (!string.IsNullOrEmpty(sessionID))
            {
                //获取Redis中对应的登录信息
                Model.users model = CacheHelperRedis.Get <Model.users>(sessionID);
                if (model != null)
                {
                    if (model.model_login != null)
                    {
                        if (model.model_login.login_ip.Trim() == DTRequest.GetIP().Trim())
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    //删除对应的COOKIES
                    Utils.WriteCookie(DTKeys.COOKIE_USER_INFO_REMEMBER, "", 1);
                }
            }
            else
            {
                //删除对应的COOKIES
                Utils.WriteCookie(DTKeys.COOKIE_USER_INFO_REMEMBER, "", 1);
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 取得当前用户准确信息
        /// </summary>
        public Model.users GetUserInfo(bool needNew = true)
        {
            Model.users_login modellogin = new Model.users_login();
            //通过Cookies获得SessionID
            string sessionID = Utils.GetCookie(DTKeys.COOKIE_USER_INFO_REMEMBER);

            if (!string.IsNullOrEmpty(sessionID))
            {
                //获取Redis中对应的登录信息
                Model.users model = CacheHelperRedis.Get <Model.users>(sessionID);
                if (model != null)
                {
                    if (model.model_login != null)
                    {
                        if (model.model_login.login_ip.Trim() == DTRequest.GetIP().Trim())
                        {
                            return(needNew ? new BLL.users().GetModel(model.id) : model);
                        }
                    }
                }
            }
            return(null);
        }
예제 #3
0
 /// <summary>
 /// 根据MD5值下载文件并显示
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         //获得来源参数
         string FileHashValue = HttpContext.Current.Request.Url.Query.ToString();
         if (FileHashValue.StartsWith("?"))
         {
             FileHashValue = FileHashValue.Substring(1);
         }
         //判断来源HASH是否为空
         if (string.IsNullOrEmpty(FileHashValue))
         {
             Response.End();
         }
         //判断来源Hash是否存在于缓存
         Model.files model = CacheHelperRedis.Get <Model.files>(fileCacheName, FileHashValue);
         BLL.files   bll   = new BLL.files();
         if (model == null)
         {
             model = bll.GetModel(FileHashValue);
             if (model != null)
             {
                 //写入缓存
                 CacheHelperRedis.Insert(fileCacheName, FileHashValue, model);
             }
         }
         //根据文件信息下载文件
         if (model != null)
         {
             //增加文件访问次数
             bll.UpdateField(model.id, "file_usetimes=file_usetimes+1");
             //检测是否被禁用或者删除
             if (model.file_state != -1)
             {
                 //从原始服务器上下载文件
                 remoteSaveAs(model);
                 if (model.file_type == 0)
                 {
                     //如果是图片类型则进行缓存控制并输出
                     string suffix = Utils.GetFileExt(model.file_path);
                     Response.ContentType = string.Format("image/{0}", suffix.ToLower().Equals("png") ? "x-png" : suffix);
                     DateTime contentModified = System.IO.File.GetLastWriteTime(Utils.GetMapPath(model.file_path));
                     if (IsClientCached(contentModified))
                     {
                         Response.StatusCode      = 304;
                         Response.SuppressContent = true;
                     }
                     else
                     {
                         Response.Cache.SetETagFromFileDependencies();
                         Response.Cache.SetAllowResponseInBrowserHistory(true);
                         Response.Cache.SetLastModified(contentModified);
                         FileStream fs     = new FileStream(Utils.GetMapPath(model.file_path), FileMode.Open, FileAccess.Read);
                         byte[]     byData = new byte[fs.Length];
                         fs.Read(byData, 0, byData.Length);
                         fs.Close();
                         System.IO.MemoryStream ms  = new System.IO.MemoryStream(byData);
                         System.Drawing.Image   img = System.Drawing.Image.FromStream(ms);
                         img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                         Response.BinaryWrite(ms.ToArray()); //新增内容
                         img.Dispose();
                     }
                 }
                 else
                 {
                     //其它类型文件则直接提供下载
                     Response.Clear();
                     Response.Buffer = true;
                     Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(model.file_name, System.Text.Encoding.UTF8));
                     Response.WriteFile(Server.MapPath(model.file_path));
                     Response.Flush();
                     Response.Close();
                 }
             }
         }
         Response.End();
     }
     catch
     {
         Response.End();
     }
 }