我想在ASP.NET应用程序中记录我的服务器名称,我使用多服务器和负载平衡,因此我需要记录服务器名称。在ASP.NET中获取服务器名称的不同方式
但是,获得服务器名称的这些方法有什么区别?
哪一个是真的或更好的登录?
有什么想法吗?
或其他方式?
System.Environment.MachineName
Server.MachineName
System.Net.Dns.GetHostName()
也有另一种方式,但并不总是返回正确的服务器名称:
Request.ServerVariables["SERVER_NAME"]
System.Net.Dns.GetHostEntry(Request.ServerVariables("SERVER_NAME")).HostName
System.Net.Dns.GetHostEntry(Request.ServerVariables("LOCAL_ADDR")).HostName
看起来,这将使你**访问http // subdomain.host.tld [:端口] **实际。例如: 'HttpContext.Current.Request.Url.ToString().Split('/') {string [4]} [0]:“http:” [1]:“” [2]: “localhost:58905” [3]:“default.aspx” – fortboise