var test1 = HttpContext.Features.Get();
var test2 = HttpContext.Connection.RemoteIpAddress;
When running the applicat
In ASP.NET Core 2.0
project you need to add package Microsoft.AspNetCore.HttpOverrides and add this code to your Configure
method:
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
What you're seeing is accurate, if not useful. Connections termination at IIS, which then forwards to Kestrel, the v.next web server, so connections to the web server are indeed from localhost.
What you need to do is enable support for X-Forwarded-For
Microsoft.AspNet.HttpOverrides
packageIn your Configure()
method add
app.UseOverrideHeaders(new OverrideHeaderMiddlewareOptions
{
ForwardedOptions = ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto
});
Note that this package will change in RC2 to make it safer to use.
That is because of you are trying to connect from localhost. If you have another computer in same LAN, try to connect with this pc but use user ip instead of localhost.