Getting 127.0.0.1 when using HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress
<p>I am using asp.net core with mvc. I am trying to get the IP address using the below code.</p>

<pre><code>var ipAddress = HttpContext.Features.Get&lt;IHttpConnectionFeature&gt;()?.RemoteIpAddress?.ToString();
</code></pre>

<p>Its always returning ::1 which means 127.0.0.1 on my local machine which is fine. But now I have hosted it on azure cloud only for testing using my testing azure account and it is still giving me 127.0.0.1.</p>

<p>What I am doing wrong?</p>

<p><strong>project.json</strong></p>

<pre><code>    {
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702",
      "author": [ "Musaab Mushtaq", "Programmer" ],
      "type": "platform"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final",
    "DeveloperForce.Force": "1.3.0",
    "Microsoft.Framework.Configuration": "1.0.0-beta8",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "IntegraPay.Domain": "1.0.0-*"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8",
        "net45"
      ],
      "dependencies": {
      }
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config",
      "config.json",
      "Views"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
</code></pre>

<p><strong>Startup.cs</strong></p>

<pre><code>  public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure&lt;ForwardedHeadersOptions&gt;(option =&gt; { option.ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForward‌​edFor; });
            services.AddMvc();
            services.AddSingleton(provider =&gt; Configuration);
            services.AddTransient&lt;IRegistrationRepository, ServiceUtilities&gt;();
            services.AddTransient&lt;IClientServiceConnector, ClientServiceValidation&gt;();
        }

        private IClientServiceConnector ForceClientService { get;set; }
        private IConfiguration Configuration { get; set; }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment enviroment)
        {
            app.UseStaticFiles();
            if (enviroment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Registration/Error");
            }

            app.UseRuntimeInfoPage("/Info");
            app.UseFileServer();
            ConfigureRestAuthenticationSetting(enviroment);
            app.UseMvc(ConfigureRoutes);
            app.Run(async (context) =&gt;
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

        private void ConfigureRestAuthenticationSetting(IHostingEnvironment enviroment)
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(enviroment.ContentRootPath)
                .AddJsonFile("config.json");
            Configuration = config.Build();
        }

        private void ConfigureRoutes(IRouteBuilder routeBuilder)
        {
            routeBuilder.MapRoute("Default", "{controller=Registration}/{action=Index}/{formId?}");
        }


    }
</code></pre>