您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ASP.NET 获取 客户端IP

2024/5/16 5:23:28发布15次查看
string requestclientipaddress = httpcontext.current.request.servervariables["http_x_forwarded_for"]; if (string.isnullorempty(requestclientipaddress)) requestclientipaddress = httpcontext.current.request.servervariables["remote_addr"]; if (string.isnullorempty(requestclientipaddress)) requestclientipaddress = httpcontext.current.request.userhostaddress;
经过测试  存在负载均衡的时候 ,httpcontext.current.request.servervariables[http_x_forwarded_for] 取出的是真实的客户端 ip地址 ,而httpcontext.current.request.servervariables[remote_addr] 和 httpcontext.current.request.userhostaddress 取出的是被分配的保留地址
注:x-forwarded-for:简称xff头,它代表代表客户端,也就是http的请求端真实的ip,只有在通过了http 代理或者负载均衡服务器时才会添加该项
以上就是asp.net 获取 客户端ip的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product