Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

httprequest.UserHostName in .net core

Couldn't find the UserHostName property on HttpRequest. And nothing about it in any forums. Has this been dropped? Any idea?

like image 654
My3 Avatar asked Feb 05 '23 20:02

My3


1 Answers

The accepted answer is not correct. someHttpContext.Request.Host corresponds to the Host header used in the HTTP request. For example: fetching http://example.org/test will result in example.org.

UserHostName used to return the DNS hostname of the client IP address making the request (which is someHttpContext.Connection.RemoteIpAddress). It looks as though the only recourse is to manually resolve the DNS hostname from the IP address with e.g. Dns.GetHostEntry.

like image 70
Jesper Avatar answered Feb 07 '23 10:02

Jesper