Request.ServerVariables["SERVER_NAME"] is always localhost
<p>I'm developing an ASP.NET 3.5 application with Visual Studio 2008.</p>

<p>My default page has some redirection code in the Page_Load method:</p>

<pre><code>    protected void Page_Load(object sender, EventArgs e)
    {

        string sname = Request.ServerVariables["SERVER_NAME"].ToLower();

        if (sname.ToLower().Contains("intranet"))
        {
        Response.Redirect("/intranet/Default.aspx");
        }
        else if ((sname.ToLower().Contains("extranet")))
        {
            Response.Redirect("/extranet/Default.aspx");
        }
        else {
            Response.Redirect("/web/Default.aspx");
        }
    }
</code></pre>

<p>I've modified my hosts file so that intranet and extranet redirect to my local machine. </p>

<pre><code>127.0.0.1       intranet
127.0.0.1       extranet
</code></pre>

<p>I then type the URL <a href="http://extranet" rel="nofollow">http://extranet</a> in my browser.</p>

<p>However, the problem is that the server variable value returned from Request.ServerVariables["SERVER_NAME"] is always "localhost" and not "extranet"</p>

<p>Any help on how to get the right value?</p>

<p>Many thanks</p>
