N
N
Nik Faraday2021-10-25 21:16:19
.NET
Nik Faraday, 2021-10-25 21:16:19

How to get user's IP address via httpContextAccessor in asp.NET Core?

Good evening!

I had a task to log an error and the IP address of the user in which it occurred.
The bottom line is that I can’t figure out how to get an IP address through httpContextAccessor (The task is to get an IP through it).

There was one option that ended up giving me ::1 (httpContextAccessor.HttpContext.Connection.RemoteIpAddress) , is that correct? I doubt it, because through the Dns class I received more detailed information about IP addresses (Dns.GetHostEntry(Dns.GetHostName()).AddressList())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-10-25
@NikFaraday

There was one option that ended up giving me ::1 (httpContextAccessor.HttpContext.Connection.RemoteIpAddress) , is that correct?

Yes, if you requested from localhost to localhost.
I doubt it, because through the Dns class I received more detailed information about IP addresses (Dns.GetHostEntry(Dns.GetHostName()).AddressList())

And what does DNS have to do with it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question