I have been trying to figure this out but cannot find a reliable way to get a clients IP address when making a request to a page in asp.net that works with all servers.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
One method is to use Request object:
protected void Page_Load(object sender, EventArgs e)
{
lbl1.Text = Request.UserHostAddress;
}
回答2:
IpAddress=HttpContext.Current.Request.UserHostAddress;
回答3:
Request.ServerVariables["REMOTE_ADDR"]
To access an index or property on C#, you should use [ ] instead of ( )
回答4:
Use this code:
public static string GetIpAddress()
{
return HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : "";
}
回答5:
System.Web.HttpContext.Current.Request.UserHostAddress;