• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 50
  • Last Modified:

How to ensure to always get domain name when using Url.Authority or Url.Host with Asp.Net

Microsoft's documentation states that it may return either the Host name or the IP address but it doesn't say how the framework determines which one to return. I'm having a problem in a production environment where Url.Authority returns the host name sometimes and at other times returns the IP address.

I need to ensure that it returns the host name every time. I've created a workaround for the moment but its not ideal, I need to figure out how to fix this.

I'm using the .NET Framework version 4.6.1 in all environments.
1 Solution
Dennis AriesCEO @ Arkro ITCommented:
Basicly? You can't. The authority will return the part of the called URI and if that contains just the IP instead of the hostname, then the only option is to reverse lookup the ip to a hostname.

However, an IP-address can be mapped to multiple hostnames making this a dodgy practice unless you manage the DNS yourself.

DnsGetHostEntry can resolve the IP to hostnames but I assume you already use that as the mentioned workaround.


Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now