服务器的DNS哪里ASP.NET应用程序运行 [英] DNS of the server where ASP.NET application is run

查看:196
本文介绍了服务器的DNS哪里ASP.NET应用程序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何去知道ASP.NET运行应用程序的服务器?DNS名称

How to get to know DNS name of the server where ASP.NET application is run?

我想获得字符串www.somehost.com如果我的应用程序的网址是的http:/ /www.somehost.com/somepath/application.aspx

I want to get string "www.somehost.com" if my application URL is http://www.somehost.com/somepath/application.aspx

有服务器的某些属性,Contex的,Session或为该请求对象?

Is there some property of Server, Contex, Session or Request objects for this?

谢谢!

推荐答案

这将让你的DNS IP为承载该网站的服务器

This will get you the DNS IP for the server that is hosting the web site

void GetDNSServerAddress()
    {
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface ni in nics)
        	{
        		if (ni.OperationalStatus == OperationalStatus.Up)
        		{
        			IPAddressCollection ips = ni.GetIPProperties().DnsAddresses;

        			foreach (System.Net.IPAddress ip in ips)
        			{
        				Console.Write(ip.ToString());
        			}
        		}
        	}
    }

不过,在写这篇香港专业教育学院刚刚看到您的编辑岗位,所以我想这是你所追求的无非是:

However, while writing this ive just seen your edited post, so i think this is what you are after is simply:

string host = Request.Url.Scheme + "://" + Request.Url.Host;

希望这有助于!

这篇关于服务器的DNS哪里ASP.NET应用程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆