请教C#.net 显示客户端机器名、IP??-------------------------------
以下VS2008调试时正常但上传到网站运行里报错??
string strHostName = Request.ServerVariables.Get("Remote_Host").ToString();
string strAddr = Request.ServerVariables.Get("Remote_Addr").ToString();
string strHostName = Page.Request.UserHostName;
string strAddr = Page.Request.UserHostAddress;-------------------------
以下只能取到主机的机器名
string strHostName = Dns.GetHostName(); //得到本机的主机名 
IPHostEntry ipEntry = Dns.GetHostByName(strHostName);               
string strAddr = ipEntry.AddressList[0].ToString();
 
 

解决方案 »

  1.   

    不会的。我试过的。你还用到了什么。或都你的IIS配置查一下
      

  2.   

    //IP地址检测
            String ClientIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (ClientIP == null || ClientIP == "")
            {
                ClientIP = Request.ServerVariables["REMOTE_ADDR"];
            }
      

  3.   

    我测试了好几次的,不知道什么原因??大家有没有完整的代码??
    以下VS2008调试时正常但上传到网站运行里报错?? 
    string strHostName = Request.ServerVariables.Get("Remote_Host").ToString(); 
    string strAddr = Request.ServerVariables.Get("Remote_Addr").ToString(); 
    string strHostName = Page.Request.UserHostName; 
    string strAddr = Page.Request.UserHostAddress;