2009-10-26 51 views

回答

9
HttpContext.Current.Request.UserHostAddress; 

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; 

拿到機器的IP地址,而不是代理使用以下代碼

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 
+0

@Lance:好點。更多的信息在這裏:http://en.wikipedia.org/wiki/X-Forwarded-For – 2009-10-26 04:06:15

+0

比你先生蘭斯哈珀它工作,但是第二個第一個和第三個它不工作 – 2009-10-26 04:09:07

3

HttpContext.Current.Request.UserHostAddress

+1

請注意,對於IIS7,本地主機的'Request.UserHostAddress'返回':: 1'而不是'127.0.0.1'。 – 2009-10-26 04:04:08

+0

雅正在工作Mr. o.k.w – 2009-10-26 04:13:13

2

嘗試:

Request.ServerVariables["REMOTE_ADDR"].ToString() 
+0

謝謝你正在工作Mr.Jay Riggs – 2009-10-26 04:09:40