views:

479

answers:

7

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!

A: 

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

dove
A: 

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.

John Sheehan
A: 

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.

Use the 'Add comment' feature to respond to individual answers
John Sheehan
+1  A: 

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

Michael Haren
A: 

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);
DavGarcia
A: 

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.

A: 

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.