来自httpheader的请求的ip地址
我正在尝试获取来自 httpheader 的请求的 IP 地址。如果值为 x,则执行某些操作,如果不是,则执行其他操作。有人可以帮我吗?
I am trying to get the IP address of the request coming in from the httpheader. If value is x do something, if not do somthing else. Can anyone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有帮助吗?看起来很简单。
从链接来看,有几种不同的方式:
HttpContext.Current.Request.UserHostAddress;
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
HttpContext .Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
Does this help? it seems pretty straight forward.
From the link, there are a few different ways:
HttpContext.Current.Request.UserHostAddress;
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
您可能需要查看此处。 HTTP 标准没有将源地址定义为协议的一部分。事实上 HTTP 与 IPv4/IPv6 根本没有直接关系。
一般来说,网络服务器很容易就能知道套接字另一端(网络浏览器所在的一端)的网络地址。它不使用 HTTP 来执行此操作,而是使用操作系统网络堆栈的功能。
对于 ASP.NET,您应该能够找到请求来自的 IP 地址。您可以尝试查看 System.Web.HttpRequest.UserHostAddress
You might want to look here. The HTTP standards do not define the source address as part of the protocol. Infact HTTP does not directly relate to IPv4 /IPv6 at all.
Generally, a webserver will easily be able to tell the network address of the other end of the socket ( the end where the web browser is ). It does not use HTTP to do this, rather it will use features of the OS's networking stack.
In the case of ASP.NET you should be able to find the IP address where the request came from. You might try looking at System.Web.HttpRequest.UserHostAddress