开发者

Create URI with machine name and .domain name

开发者 https://www.devze.com 2022-12-27 06:49 出处:网络
maybe I will not correct explain a problem, maybe somebody help me explain this problem. So, I have next task: create instance of URI with name of PC, like this:

maybe I will not correct explain a problem, maybe somebody help me explain this problem. So, I have next task: create instance of URI with name of PC, like this:

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

But if开发者_运维百科 PC in domain I need to use extended PC name like this: pcname.company.com

For this case I used next code

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

And here I found problem :(

Name of domain can be company.com but can be company_system. I use this syntax for different cases for example : If I wont to login on my PC I can write myname@company.com and I can write company_system\myname.

And question:

How to find domain name in format like this company.com because by default Environment.UserDomainName returns domain name like company_system?

Thank you!

Regards,

Jitm


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

GetHostEntry returns name of PC with domain and domain in correct format like this:

pcname.company.com

0

精彩评论

暂无评论...
验证码 换一张
取 消