C#返回当前页面是否是跨站提交

C#判断是否是跨站提交



   /// <summary>
        /// 返回当前页面是否是跨站提交
        /// </summary>
        /// <returns>当前页面是否是跨站提交</returns>
        public static bool IsCrossSitePost()
        {

            // 如果不是提交则为true
            if (!UrlHelper.IsPost())
            {
                return true;
            }
            return IsCrossSitePost(UrlHelper.GetUrlReferrer(), UrlHelper.GetHost());
        }

        /// <summary>
        /// 判断是否是跨站提交
        /// </summary>
        /// <param name="urlReferrer">上个页面地址</param>
        /// <param name="host">论坛url</param>
        /// <returns></returns>
        public static bool IsCrossSitePost(string urlReferrer, string host)
        {
            if (urlReferrer.Length < 7)
            {
                return true;
            }
            Uri u = new Uri(urlReferrer);
            return u.Host != host;
        }