c# - 读取 X-Forwarded-For header

标签 c# asp.net

我想读取 X-Forwarded-For 的值请求中的 header 值。

我试过了

HttpContext.Current.Request.Headers["X-Forwarded-For"].Split(new char[] { ',' }).FirstOrDefault();  

在 C# 中。

或者我是否需要用 ":" 拆分 header 并取第二个字符串? 我问这个是因为,维基百科说

The general format of the field is: X-Forwarded-For: client1, proxy1, proxy2

最佳答案

返回的格式是client1, proxy1, proxy2

所以你用逗号分开,第一个看到你客户端的ip。

关于c# - 读取 X-Forwarded-For header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6316796/

相关文章:

c# - 异步委托(delegate)什么时候应该使用回调模式?

c# - 如何将 System.Byte[] 转换为图像? (C# 窗口窗体)

c# - 如何在没有回调的情况下异步发出 Web 请求

c# - Web API 2 路由属性不起作用

c# - Union 或 Concat 中的类型不能用层次结构构造

asp.net - "System.Net.HttpListener"在 IAppBuilder 属性中不可用

asp.net - 背景图像不工作

c# - DateTime 精度差异.NET 与 Java

c# - 无法写入新的 MemoryStream - 流已关闭

c# - 将更多项目添加到 ListView 中的同一行和同一列