コード例 #1
0
        /// <summary>
        /// 重写虚方法,此方法在Init事件执行
        /// </summary>
        protected override void InitPage()
        {
            action = DTRequest.GetQueryString("action");

            //获得最后登录日志
            DataTable dt = new BLL.user_login_log().GetList(2, "user_name='" + userModel.user_name + "'", "id desc").Tables[0];

            if (dt.Rows.Count == 2)
            {
                curr_login_ip  = dt.Rows[0]["login_ip"].ToString();
                pre_login_ip   = dt.Rows[1]["login_ip"].ToString();
                pre_login_time = dt.Rows[1]["login_time"].ToString();
            }
            else if (dt.Rows.Count == 1)
            {
                curr_login_ip = dt.Rows[0]["login_ip"].ToString();
            }
            //未完成订单
            total_order = new BLL.orders().GetCount("user_name='" + userModel.user_name + "' and status<3");
            //未读短信息
            total_msg = new BLL.user_message().GetCount("accept_user_name='" + userModel.user_name + "' and is_read=0");

            //退出登录==========================================================
            if (action == "exit")
            {
                //通过Cookies获得SessionID
                string sessionID = Utils.GetCookie(DTKeys.COOKIE_USER_INFO_REMEMBER);
                //清空对应的缓存内容
                CacheHelperRedis.Remove(sessionID);
                //清除Cookies
                Utils.WriteCookie(DTKeys.COOKIE_USER_INFO_REMEMBER, "", -43200);
                //自动登录,跳转URL
                HttpContext.Current.Response.Redirect(linkurl("login"));
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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();
     }
 }