C#判断请求来源是否在允许的域名中

判断请求来源是否允许



  #region 判断请求来源是否在允许的域名中
        /// <summary>
        /// 判断请求来源是否允许,允许则返回true
        /// </summary>
        public static bool IsAllowDomain
        {
            get
            {
                if (HttpContext.Current.Request.UrlReferrer == null) return false;
                string reqDomain = HttpContext.Current.Request.UrlReferrer.Host.ToLower();
                return isAllowUrl(reqDomain);
            }
        }
        /// <summary>
        /// 判断请求来源是否允许
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static bool isAllowUrl(string url)
        {
            string[] AllowDomains = new string[] {
                "yunjson.com"
            };
            foreach (string str in AllowDomains)
            {
                if (url.EndsWith(str)) return true;
            }
            return false;
        }
        #endregion


原文链接:C#判断请求来源是否在允许的域名中