使用C#的客户端IP [英] Client IP using C#
本文介绍了使用C#的客户端IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能在C#中客户机的IP地址?
我想保持一个日志登记为我的网上申请,并保持记录系统的IP地址,我想获得客户端的IP地址......
先谢谢了...
解决方案
HttpContext.Current.Request.UserHostAddress
这不会试图兼顾代理。为此,你可以使用 Request.ServerVariables [HTTP_X_FORWARDED_FOR]
。但是,请确保你不相信那盲目的,因为它可能是伪造的。这是更好地保持IP地址白名单,而您信任它。
How can i get IP address of client machine in C#.? I want to keep a log register for my online application and to keep IP address of logging system i want to get the IP address of client....
Advance Thanks...
解决方案
HttpContext.Current.Request.UserHostAddress
This doesn't attempt to take into account proxies. For that, you can use Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
. However, make sure you're not trusting that blindly, since it could be forged. It's better to keep a whitelist of IPs for which you trust it.
这篇关于使用C#的客户端IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文