Create URI with machine name and domain name .domain

Maybe I won't fix the problem, maybe someone can help me explain this problem. So, I have the following task: create an instance of a URI named PC like:

baseAddress = new Uri(string.Format("http://{0}:{1}", Dns.GetHostName() ,port ));

      

But if the PC is in the domain I need to use the extended PC name like this:    pcname.company.com

In this case, I used the following code

baseAddress = new Uri(string.Format("http://{0}:{1}", Dns.GetHostName() + "." + Environment.UserDomainName ,port ));

      

And here I found the problem :(

The domain name can be company.com , but it can be company_system . I use this syntax for different cases, for example: If I am not logged in to my PC, I can write myname@company.com and I can write company_system \ myname .

And the question:

How do I find the domain name in the format company.com because it Environment.UserDomainName

returns the domain name by default like company_system ?

Thanks!

Yours faithfully,

Jitm

+2


a source to share


1 answer


System.Net.Dns.GetHostEntry (Dns.GetHostName ()). HostName

GetHostEntry returns PC name with domain and domain in correct format:



pcname.company.com

+1


a source







All Articles