What's the difference between ServerVariables["HTTP_HOST"] and ServerVariables["SERVER_NAME"]?

Pure.Krome picture Pure.Krome · May 23, 2011 · Viewed 7.4k times · Source

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?

Answer

DSharper picture DSharper · May 23, 2011

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