如何通过HTTP_X_FORWARDED_FOR从IIS ASPX页面 [英] How to pass HTTP_X_FORWARDED_FOR to aspx pages from IIS

查看:266
本文介绍了如何通过HTTP_X_FORWARDED_FOR从IIS ASPX页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Amazon ELB运行自己的网站。我需要捕获客户端的IP地址,我们在网站上做什么 - 这不是很理想,但我们肯定需要的IP现在。

I have my site running on Amazon ELB. I need to capture client's IP address for something we do on the site - it's not ideal, but we definitely need the IP for now.

这使用一个专用的服务器上工作的伟大。但自从搬到ELB,我只得到ELB的内部IP地址作为客户端的IP地址时,我用 Request.UserHostAddress

This used to work great on a dedicated server. But since moving to ELB, I only get ELB's internal ip address as client's ip address when I use Request.UserHostAddress

去一些博客的我加了 X-转发,对于,即使我的IIS日志中有正确的客户端IP地址,该IP不通过实际的网页。

Going from some blogs I added X-Forwarded-For and even though my IIS logs have right client IP, that IP is not passed to the actual web pages..

逸岸,则在头部没有这样的字段..或任何接近,在标题中。

Infact, there is no such field in the header.. or anything close to that in the header.

在检查 Request.Headers.ToString()给我我的会话cookie,其他的饼干,客户端浏览器(正确地)和其他类似的东西,但没有什么任何IP 。事实上,我甚至不能看到ELB的静态IP。

Inspecting the Request.Headers.ToString() gives me my session cookies, other cookies, client browser (correctly) and other such things but there is nothing about any IP. In fact, I cannot even see the elb's static ip.

Request.Headers [HTTP_X_FORWARDED_FOR] 始终为空,可以理解。

Request.Headers["HTTP_X_FORWARDED_FOR"] is always null, understandably.

我如何从C#真正的客户端IP,好吗?

How do I get the real client IP from C#, please?

推荐答案

我做了一件前几天相似!

I did something similar a few days ago!

我不得不使用 Request.ServerVariables ,并查找 REMOTE_ADDR 来找到客户端IP。

I had to use Request.ServerVariables and look for REMOTE_ADDR to find the client IP.

事情是这样的:

if (Request.ServerVariables["REMOTE_ADDR"] != null)
{
    string userIP = Request.ServerVariables["REMOTE_ADDR"]; 
}

这是为我工作。

这篇关于如何通过HTTP_X_FORWARDED_FOR从IIS ASPX页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆