代码之家  ›  专栏  ›  技术社区  ›  Arash

配置ASP.NET核心以使用代理服务器和负载平衡器

  •  0
  • Arash  · 技术社区  · 7 年前

    我已经遵循了上面解释的所有步骤 this Microsoft's documents page 通过调用 HttpContext.Connection.RemoteIpAddress ,但我一直在获取的环回IP地址 ::1 . 只有一个奇怪的场景让我得到远程客户机的IP地址,这是通过下面的服务配置代码实现的,其中 ForwardedForHeaderName 由初始化 X-Forwarded-For-Custom-Header-Name 这对我来说毫无意义!

    services.Configure<ForwardedHeadersOptions>(options =>
    {
        options.ForwardLimit = 2;
        options.ForwardedForHeaderName = "X-Forwarded-For-Custom-Header-Name";
    });
    

    全部 source code is found in this github repo 我想知道要成功地通过删除“x-forwarded-for-custom-header-name”来获取远程IP地址必须做什么具体的更改,以及为什么这样的字符串会获得IP地址!

    2 回复  |  直到 7 年前
        1
  •  1
  •   Martin Ullrich    7 年前

    X-Forwarded-For-Custom-Header-Name X-Forwarded-For

    X-Real-IP

    dotnet publish web.config

        2
  •  0
  •   n0rd    7 年前

    X-Forwarded-For ForwardedForHeaderName

    services.Configure<ForwardedHeadersOptions>(options =>
    {
        options.ForwardedHeaders = 
            ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
    });