(332) 331-8677

Get Client IP Address in ASP.NET Core

In the Startup.cs file

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

In the Razor View file

var remoteIpAddress = Context.Connection.RemoteIpAddress.ToString();