如何取得Request.ServerVariables["HTTP_REFERER"]的域名部份如Request.ServerVariables["HTTP_REFERER"]值为http://www.baidu.com/42/wo.html如何把http://www.baidu.com/取出来 后面的不要

解决方案 »

  1.   

    用js很简单:<script>
    var a = document.createElement("a");
    a.href="http://www.baidu.com/42/wo.html";
    alert("http://" + a.hostname);
    </script>
    弹出:http://www.baidu.com
      

  2.   


    using System.Text.RegularExpressions; //引用命名空间string url = "http://www.baidu.com/42/wo.html";         
    Match m = Regex.Match(url, @"(http://)[\w\.]+[/]");           
    Response.Write(m.ToString());
      

  3.   

     Match match = Regex.Match(uri, @"((http(s)?://)?)+[\w-.]+[^/]");//, RegexOptions.IgnoreCase
    domainName = match.Value;