Esempio n. 1
0
        /// <summary>
        /// 监测是否来自浏览器
        /// </summary>
        /// <param name="actionContext"></param>
        private bool CheckIsComeFromWebBrowser(ActionExecutingContext actionContext)
        {
            bool   result    = false;
            string userAgent = actionContext.HttpContext.Request.Headers[HttpServerProxy.RequestHeaderKeyUserAgent];

            //验证UA
            if (string.IsNullOrEmpty(userAgent))
            {
                return(false);
            }

            //验证请求参数sign
            string requestSign = actionContext.HttpContext.Request.GetQuery <string>("sign");

            if (string.IsNullOrEmpty(userAgent))
            {
                return(false);
            }
            else
            {
                //验证sign 标识
                var isValidSign = WorkContext.CheckIsValidRequestSign(requestSign);
                if (false == isValidSign)
                {
                    return(false);
                }
            }

            //验证cookie 标识
            var cookieWebbrowserSign = actionContext.HttpContext.GetCookie <string>(Contanst.Cookie_Key_BrowserSign);

            if (string.IsNullOrEmpty(cookieWebbrowserSign))
            {
                return(false);
            }

            try
            {
                //这是加密内容cookieWebbrowserSingn = string.Concat(WorkContext.SiteName, ":", DateTime.Now.ToString());
                //解密cookie
                string signText = LZString.Decompress(cookieWebbrowserSign, true);

                if (!string.IsNullOrEmpty(signText))
                {
                    if (signText.Contains(WorkContext.SiteName))
                    {
                        string time = signText.Split('|')[1];//获取里面的时间 超过3小时 必须刷新页面 否则过期
                        if (!string.IsNullOrEmpty(time) && DateTime.Now.Subtract(time.ToDatetime()).Hours < 3)
                        {
                            result = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }


            return(result);
        }