ip address of request from httpheader

倾然丶 夕夏残阳落幕 提交于 2019-12-05 22:10:05

问题


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?


回答1:


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




回答2:


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"];



来源:https://stackoverflow.com/questions/5585916/ip-address-of-request-from-httpheader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!