15

I'm confused about the difference between these two server variables. Checking the IIS documentation, it states :-

HTTP_HOST

Returns the name of the Web server. This may or may not be the same as SERVER_NAME depending on type of name resolution you are using on your Web server (IP address, host header).

SERVER_NAME

The server's host name, DNS alias, or IP address as it would appear in self-referencing URLs.

Could someone provide some examples how they can be different?

We have 2 IIS webservers in our web farm .. and each one has 2 websites (identical of course, per server).

For each website has around 5 or so bindings.

So .. what would the values be? what's the difference?

Community
  • 1
  • 1
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • 1
    Realted: http://stackoverflow.com/questions/5710906/newbie-net-question-variable-thats-equivalent-of-sessionserver-name – Simeon May 23 '11 at 08:39

3 Answers3

2

Just found that enabling tracing in one of IIS hosted aspx page that SERVER_NAME returns just the server name whereas HTTP_HOST returns servername:port that site runs. to enable trace set

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" Trace="true" %>

note the Trace value

DSharper
  • 3,177
  • 9
  • 29
  • 47
1

I don't know about ASP.NET, but in PHP, $_SERVER['HTTP_HOST'] is what the client sent in the HTTP Host header, while $_SERVER['SERVER_NAME'] is determined by the webserver configuration.

Oswald
  • 31,254
  • 3
  • 43
  • 68
  • so if i hack my hosts file by adding a custom entry that points to another webserver .. and then enter that domain into my browser .. and assuming the target webserver is not restricted by host-headers .. then when I connect, then HTTP_HOST value will be the domain i entered into the browser -> which is my custom one. ??? – Pure.Krome May 24 '11 at 00:21
  • Yes. A simpler way to achieve the same is to directly [tamper](https://addons.mozilla.org/en-us/firefox/addon/tamper-data/) with the HTTP request. – Oswald May 28 '11 at 18:25
0

HTTP_HOST is HTTP Host Header, can be changed via DNS (add a domain and poit to your server) or just via HOSTS file on your computer.

SERVER_NAME on Windows is the Machine name. you can see the name (or change it) via Right Click on My Computer (or Computer on Win10+), and Properties.

Moshe L
  • 1,797
  • 14
  • 19