zoukankan      html  css  js  c++  java
  • 防止AutoPost

    public string CheckUrl()
            {
                Uri ComeUrl = HttpContext.Current.Request.UrlReferrer;
                string cUrl = string.Empty;
                HttpContext context = HttpContext.Current;

                if (context.Request.Browser.Browser.ToLower() == "unknown")
                {
                    return "浏览器未知!";
                }

                if (context.Request.Browser.Platform.ToLower() == "unknown")
                {
                    return "操作系统未知!";
                }

                if (context.Request.HttpMethod.ToUpper() != "POST")
                {
                    return "提交错误!";
                }

                if (ComeUrl == null)
                {
                    return "请从UrL访问!";
                }
                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);

                    if (result != 0)
                    {
                        return "请从请从正确UrL访问!";
                    }
                }

                return "";
            }

  • 相关阅读:
    BZOJ 4260: Codechef REBXOR(01trie+思维)
    17个CSS知识点整理
    30个很棒的jQuery幻灯片放映插件
    gitHub客户端Desktop的安装使用总结 ---基础篇
    jQuery 瀑布流动态加载效果
    【转】自适应网页设计(Responsive Web Design)
    响应式布局这件小事
    查找指定节点之后的下一个元素节点getNextElement(node)
    转 JavaScript 运动框架 Step by step
    JS常用函数封装
  • 原文地址:https://www.cnblogs.com/zwei1121/p/1271965.html
Copyright © 2011-2022 走看看