How to Get Client IP Address in ASP.NET Core 2.0 Razor Pages

In this short post, find the code to get client IP address in ASP.NET Core 2.0 Razor pages. You need to inject IHttpContextAccessor in razor page using @inject. You can inject a service into a view using the @inject directive. You can think of @inject as adding a property to your view, and populating the property using DI.