ZhenL
ZhenL

Reputation:

Web server changed name, url return wrong host name

In our web application (asp.net), the tabs are dynamic links. The links were built like this:

finalUrl = "https://" + Request.Url.Host + "/home.aspx";

The link is ended up like:

https://server0/home.aspx

The problem is the web server's name was server0, but now it was changed to server1. Still the old server name keeps showing up. Can anyone help point out where we missed?

(etc/hosts has correct setting)

Thanks!

Upvotes: 0

Views: 1584

Answers (7)

ZhenL
ZhenL

Reputation:

At the time when "Request.Url.Host" is referenced, the host name is already changed back old server.

I found the problem lies in Metabase.xml, where the host is extracted from, if relative url is used. Then the subsequent reference of "Request.Url.Host" will reflect the value.

Upvotes: 0

ZhenL
ZhenL

Reputation:

There is probably good reason for not using relative url. I am not the original developer. And it is just that the code works everywhere including production servers but this one machine. Just want to get to the bottom of it.

Upvotes: 0

DavGarcia
DavGarcia

Reputation: 18792

Use a program like FireBug for FireFox to see the request header. Then open up your web browser and go to your application. Turn on the Net tab on FireBug to view the request values. For example, on this web site I can see:

Host stackoverflow.com
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 (.NET CLR 3.5.30729)
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
...

Thus I would expect that Request.Url.Host will be "stackoverflow.com".

As a side note, you should definitely look into using the ~/ absolute path option, a brief example:

string finalUrl = "~/home.aspx";
Response.Redirect(finalUrl);

Upvotes: 0

Michael Haren
Michael Haren

Reputation: 108246

Can I assume that there's a good reason you're not using relative URLs?

Upvotes: 1

ZhenL
ZhenL

Reputation:

dove, I made some simplification out of it. The tab will point to another virtual directory on the same machine.

John, no, it is not accessible through old host name.

Upvotes: 0

John Sheehan
John Sheehan

Reputation: 78104

Is the site still accessible through the old URL? That property is based off the URL entered, not the name of the server it's on.

Upvotes: 0

dove
dove

Reputation: 20674

If using asp.net as tagged, would you not look at using HttpRequest.ApplicationPath ? (Using System.Web)

Upvotes: 0

Related Questions