示例#1
0
 /// <summary>
 /// 获取JObject的Value
 /// </summary>
 /// <param name="obj">JObject对象</param>
 /// <param name="key">值Key</param>
 /// <returns></returns>
 public static string GetValue(JObject obj, string key)
 {
     if (!VerifyHelper.IsNull(obj) && !VerifyHelper.IsEmpty(key))
     {
         return(StringHelper.Get(obj.GetValue(key, StringComparison.InvariantCultureIgnoreCase)));
     }
     return("");
 }
示例#2
0
        /// <summary>
        /// 获取客户端IP
        /// </summary>
        public static string GetClientIP()
        {
            string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

            if (string.IsNullOrEmpty(ip))
            {
                ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            }
            if (string.IsNullOrEmpty(ip))
            {
                ip = HttpContext.Current.Request.UserHostAddress;
            }
            if (!string.IsNullOrEmpty(ip) && VerifyHelper.IsIP(ip))
            {
                return(ip);
            }
            return("127.0.0.1");
        }
示例#3
0
        /// <summary>
        /// 获取来源页面
        /// </summary>
        public static string GetRefUrl(string key = "_ref", string defaultUrl = "/", string url = null)
        {
            //如果当前请求地址中包含key
            var refUrl = GetQueryValue(key, url);

            if (string.IsNullOrWhiteSpace(refUrl) &&
                HttpContext.Current != null &&
                HttpContext.Current.Request != null &&
                HttpContext.Current.Request.UrlReferrer != null)
            {
                //ajax 访问中ajax的地址元_ref参数,但请求ajax的来源页中包含url
                var sourceRefUrl = GetQueryValue(key, HttpContext.Current.Request.UrlReferrer.ToString());
                if (!VerifyHelper.IsEmpty(sourceRefUrl))
                {
                    refUrl = sourceRefUrl;
                }
                else
                {
                    refUrl = VerifyHelper.IsAjax() ? "" : HttpContext.Current.Request.UrlReferrer.ToString();
                }
            }

            //来源页为空或为当前自己
            if (string.IsNullOrWhiteSpace(refUrl) || GetCurrentReqeustUrl().ToLower().Contains(refUrl))
            {
                refUrl = defaultUrl;
            }
            return(refUrl);

            ////如果当前请求为Ajax且来源(ajaxy请求所在页面)的地址含key
            //if (VerifyHelper.IsAjax() && string.IsNullOrWhiteSpace(url) && HttpContext.Current.Request.UrlReferrer != null)
            //{
            //    var item = UrlsHelper.GetQueryList(HttpContext.Current.Request.UrlReferrer.ToString()).FirstOrDefault(x => x.Key.ToLower() == key.ToLower());
            //    if (item != null && !string.IsNullOrWhiteSpace(item.Value))
            //    {
            //        url = item.Value;
            //    }
            //}

            ////如果当前及ajax的请求来源地址中都不包含key
        }
示例#4
0
        private static PooledRedisClientManager CreateManage(string redisUri)
        {
            if (VerifyHelper.IsEmpty(redisUri))
            {
                throw new Exception("RedisUri is Null");
            }


            var list = StringHelper.ToKeyValueList(redisUri);

            if (VerifyHelper.IsEmpty(list))
            {
                throw new Exception("RedisUri is Null");
            }

            try
            {
                var reads            = list.FirstOrDefault(x => String.Equals(x.Key, "Reads", StringComparison.CurrentCultureIgnoreCase)).Value.Split(',');
                var writes           = list.FirstOrDefault(x => String.Equals(x.Key, "Writes", StringComparison.CurrentCultureIgnoreCase)).Value.Split(',');
                var maxWritePoolSize = IntHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "MaxWritePoolSize", StringComparison.CurrentCultureIgnoreCase)).Value);
                var maxReadPoolSize  = IntHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "MaxReadPoolSize", StringComparison.CurrentCultureIgnoreCase)).Value);
                var autoStart        = BoolHelper.Get(list.FirstOrDefault(x => String.Equals(x.Key, "AutoStart", StringComparison.CurrentCultureIgnoreCase)).Value);

                PooledRedisClientManager manage = new PooledRedisClientManager(reads, writes, new RedisClientManagerConfig
                {
                    MaxWritePoolSize = maxWritePoolSize,
                    MaxReadPoolSize  = maxReadPoolSize,
                    AutoStart        = autoStart,
                });
                return(manage);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }