asp.net取得的客户端IP会是:::1呢,而不是192.168.1.17之类的(WIN7本机调试)
代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (String.IsNullOrEmpty(ip))
{
ip = Request.ServerVariables["REMOTE_ADDR"];
}
Response.Write("客户端IP地址:" + ip);
}
}
运行结果:
客户端IP地址:::1
守着星空守着你