I'm developing an ASP.NET 3.5 application with Visual Studio 2008.
My default page has some redirection code in the Page_Load method:
    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");
        }
    }
I've modified my hosts file so that intranet and extranet redirect to my local machine.
127.0.0.1       intranet
127.0.0.1       extranet
I then type the URL http://extranet in my browser.
However, the problem is that the server variable value returned from Request.ServerVariables["SERVER_NAME"] is always "localhost" and not "extranet"
Any help on how to get the right value?
Many thanks
Request.ServerVariables["HTTP_HOST"] gets the value I was looking for :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With