解决方案 »

  1.   

    添加web引用http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?op=getCountryCityByIp            IpAddressSearchWebService webService = new IpAddressSearchWebService();
                string[] strArea = webService.getCountryCityByIp(strIP);
                return strArea[1];
      

  2.   


    //这个是获取客户的IP
    string user_IP = "";
                if (Request.ServerVariables["HTTP_VIA"] != null)
                {
                    user_IP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    user_IP = Request.ServerVariables["REMOTE_ADDR"].ToString();
                }
    //下面是把这个IP到这个接口数据库进行转换为实际的地址
                string url_str = "";
                url_str = "http://whois.pconline.com.cn/ip.jsp?ip=" + user_IP;
                WebRequest request = WebRequest.Create(url_str);
                WebResponse response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
                url_str = reader.ReadToEnd();
                reader.Close();
                reader.Dispose();
                response.Close();
              Label1.Text=url_str;//这个就是获得位置了
      

  3.   

    http://whois.pconline.com.cn/ip.jsp这个接口永久免费的吗??
      

  4.   

    2楼给的webservice我用了很久了。
      

  5.   


     首先感谢楼主!小弟试了一下楼主的代码,但是Label1显示的是“本机地址”四个字。不知道哪里错了!
      

  6.   

    贴一段代码。用新浪的接口:
    if (context.Request.ServerVariables["HTTP_VIA"] != null) //得到穿过代理服务器的ip地址
                {
                    UserIP = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    UserIP = context.Request.ServerVariables["REMOTE_ADDR"].ToString();
                }string json = new HttpClient("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=" + UserIP).GetString();
                    if (StringPlus.IsNotNull(json))
                    {
                        JsonData jd = JsonMapper.ToObject(json);
                        if (jd["ret"].IsInt && (int)jd["ret"] == 1)
                        {
                            string province = jd["province"].ToString();
                            string city = jd["city"].ToString();
                            string isp = jd["isp"].ToString();
                            if (province == city)
                            {
                                address = province + " " + isp;
                            }
                            else
                            {
                                address = province + city + " " + isp;
                            }
                        }
                    }
      

  7.   

    引用“首先感谢楼主!小弟试了一下楼主的代码,但是Label1显示的是“本机地址”四个字。不知道哪里错了!”
    ======================
    你在本机运行,当然显示“本机地址”,你把程序放到服务器,然后你再访问,就显示地理位置了。
      

  8.   

    你直接在地址栏输入这个地址:
    http://whois.pconline.com.cn/ip.jsp?ip=202.105.179.122
    显示的结果是:广东省珠海市 电信IDC机房你不想要"电信IDC机房",可以截止字符串,就会得到广东省珠海市
      

  9.   


    我试了一下,但是报错!不知道是怎么回事!你把context.去掉,直接用Request吧。这个context是在ashx文件中用到的