Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 758
Pure.Krome Avatar asked May 23 '11 08:05

Pure.Krome


People also ask

What is $Http_host?

HTTP_HOST is the target host sent by the client. It can be manipulated freely by the user. It's no problem to send a request to your site asking for a HTTP_HOST value of www.stackoverflow.com . SERVER_NAME comes from the server's VirtualHost definition and is therefore considered more reliable.

What are ServerVariables?

IIS Server Variables provide information about the server, the connection with the client, and the current request on the connection. Additionally, inbound URL rewrite rules can be used to set custom server variables.

What is server variables in asp net?

ServerVariables returns important information from Request. This collection can be used to return an ASP.NET website's domain name programmatically. Possible use. Often ASP.NET code is used on many different domain names. With ServerVariables, we don't need to hard code the domain name.


2 Answers

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

like image 70
DSharper Avatar answered Oct 11 '22 21:10

DSharper


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.

like image 34
Oswald Avatar answered Oct 11 '22 21:10

Oswald