3

One uses HttpContext.Connection.RemoteIpAddress to get a client's IP address.

Microsoft.AspNetCore.Http.ConnectionInfo.RemoteIpAddress is marked as nullable.

It will be null when behind a reverse proxy server. (In that case the UseForwardedHeaders middleware must be used.)

The docs linked above just say "Can be null" - under what other conditions can it be null?

lonix
  • 14,255
  • 23
  • 85
  • 176
  • 1
    See [response at the repo](https://github.com/dotnet/aspnetcore/issues/40191). Maybe someone can add a proper answer below to explain the details described there. Basically it's for edge cases. – lonix Feb 14 '22 at 06:49

0 Answers0