防Post提交

来源:互联网 发布:网络推广架构 编辑:程序博客网 时间:2024/04/29 21:03

public static bool CheckUrl()
        {
            Uri ComeUrl = HttpContext.Current.Request.UrlReferrer;
            string cUrl;
            if (ComeUrl == null)
            { return false; }
            else
            {
                string reffer = ComeUrl.ToString();
                cUrl = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"];


                if (reffer.Substring(cUrl.Length, 1) == ":")
                {
                    cUrl += ":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString();
                }
                int lenth;
                lenth = cUrl.Length;
                cUrl += HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"];
                int result;
                result = String.Compare(reffer, 1, cUrl, 1, lenth, true);
                return (result == 0);
            }
        }