Home >Backend Development >C++ >How to Get the Client IP Address in ASP.NET Core?
Original Problem:
The traditional method, Request.ServerVariables["REMOTE_ADDR"]
, for obtaining the client IP address in ASP.NET Core MVC 6 is now obsolete.
Updated Solution:
Due to recent API updates in ASP.NET Core, a new approach is necessary to retrieve the client's IP address. As noted by Damien Edwards, the following code provides the correct solution:
<code class="language-csharp">var remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;</code>
This revised method utilizes the Connection
property within the HTTP context to successfully retrieve the remote IP address, effectively replacing the outdated Request.ServerVariables["REMOTE_ADDR"]
method.
The above is the detailed content of How to Get the Client IP Address in ASP.NET Core?. For more information, please follow other related articles on the PHP Chinese website!