access_time 2 years ago languageEnglish
more_vert

Get IP Address in ASP.NET Core 5

visibility 10,943 comment 2
This page summarize information about how to retrieve client and server IP address in ASP.NET Core 5 (.NET 5) web applications. This page is an updated version of  Get IP Address in ASP.NET Core 3.x . Client IP address can be retrieved via HttpContext.Connection object. This properties ...
thumb_up 2

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

comment Comments
9 months ago link more_vert
Raymond Raymond
web_assetArticles 583
imageDiagrams 40
forumThreads 9
commentComments 218
loyaltyKontext Points 6293
account_circleProfile
#1506 Re: Get IP Address in ASP.NET Core 5

For user OS system type, you can use User-Agent in request headers:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.38

For example the above value means Windows 10 x64 edition. 

As there are many browsers and many system types and versions, it is not easy to do a holistic parsing. What you can do is to find out the most useful ones for you based on each browser User-Agent definitions. 

For client local user machine name, it is not sent to the server in the request unless you are using Windows Authentication. Even for this authentication type, it doesn't necessarily represent the actual user name as user can use Run As to impersonate users.

Configure Windows Authentication in ASP.NET Core | Microsoft Docs

And then you can use the following approach in Razor Pages or Controllers to get user name:

string userName = HttpContext.User.Identity.Name;


format_quote

person Udaysinh access_time 9 months ago
Re: Get IP Address in ASP.NET Core 5

Very useful article . Thanks. but

How can get client System name and client local machine user name?

9 months ago link more_vert
U
Udaysinh
web_assetArticles 0
imageDiagrams 0
forumThreads 0
commentComments 1
loyaltyKontext Points 1
#1505 Re: Get IP Address in ASP.NET Core 5

Very useful article . Thanks. but

How can get client System name and client local machine user name?

timeline Stats
Page index 22.65