if(Request.ServerVariables["HTTP_REFERER"]==null)
{
非法提交
}

解决方案 »

  1.   


    if (Request.ServerVariables["HTTP_REFERER"] == null || !Request.ServerVariables["HTTP_REFERER"].ToString().Contains(Request.ServerVariables["HTTP_HOST"].ToString()))   
    {
      Server.Transfer("Error.aspx");   

      

  2.   

    7楼的方法并不完整。
    假设你的主机是:abc.xxx.com
    那么bc.xxx.com 或 c.xxx.com 还是可以递交,因为你的主机头里也包含这两个主机头。
    所以这里不能用 Contains 来判断。if (Request.HttpMethod.Equals("POST") || Request.HttpMethod.Equals("GET"))
    {
        string HTTP_REFERER = Request.ServerVariables["HTTP_REFERER"].ToString();
        if (HTTP_REFERER != "" && HTTP_REFERER != null)
        {
            HTTP_REFERER = HTTP_REFERER.Substring(HTTP_REFERER.IndexOf(@"//") + 2);
            HTTP_REFERER = HTTP_REFERER.Substring(0, HTTP_REFERER.IndexOf(@"/"));
        }
        if (HTTP_REFERER != Request.ServerVariables["HTTP_HOST"].ToString())
        {
            Server.Transfer("Error.aspx");
        }
    }另外,bc.xxx.com 或 c.xxx.com 可以通过本地DNS解析得到。
      

  3.   

    每个地方接受数据的地方是固定的吧
    就判断REFERER吧
    或者用其他的校验码