views:

334

answers:

2

UPDATED 03/04/09

In response to some comments, a sample from the master page looks like this. This is not an asp.net control, this is hard coded html

<a href="http://www.MYDOMAIN.com/about_us.asp" accesskey="u"><span class="topleft"><span class="bottomleft">About us</span></span></a>

This renders on the production server as

<a href="http://www.NEWDOMAIN.com/about_us.asp" accesskey="u"><span class="topleft"><span class="bottomleft">About us</span></span></a>

MYDOMAIN is the true domain name of our main site, NEWDOMAIN is a perfectly valid DNS entry which points to the same site.

UPDATED 02/04/09

All the URLS are absolute in the sense that they begin http://

I don't think this can be a browser issue as the actual rendered source code (viewed via view source) has been changed. Checked in both IE7/8 and Firefox 3 and witnessed same behaviour.

Original Question

I have an ASP.Net 2.0 application which has several master pages. This is essentially mocked up to look exactly like our main website, but because it runs on a different server all of the URLs for menu items etc are given absolute URLs to our main site.

This works fine on my development machine, but on the production server all of the URLs which are absolute are changing at runtime, but they still end up at the same pages when clicked.

Is this a DNS issue? Does ASP.Net do some DNS resoltion of URL's when the master page and content are merged? If so then why does it not have the same effect on my local machine, they are on the same domain.

A: 

By "absolute" I assume you mean they start with a "/" rather than a folder name?

If you are using the ASP.NET hyperlink control, then these will tend to modified to start at the application root.

Edit for comment

Can you give us an example of how the urls are being changed? i.e. From http://www.example.com/somepage.aspx to http://www.example.com/trackingpage.aspx?somequerysting - or is the domain changing? or something else?

You say "they still end up at the same pages" - so clearly things are working. Have you got any HttpHandlers registered in the web.config on your production servers that could be modifying the URLs for you so that they all go through some logging system? I.e. taking the response from the server, processing the resultant HTML, modifying all links - does it happen with simple anchor tags as well as Hyperlink controls?

Are you using a custom base page that is performing additional steps in PreRender or Render that's different on production to your developer machine that is changing the URLs?

Zhaph - Ben Duguid
No by absolute I mean absolute, "/" is still relative. These links all start "http://"
Charlie
+2  A: 

No, it's not a DNS issue, and ASP.net doesn't do any DNS resolution. That's all the responsibility of the browser you're viewing the page in.

However, there are several circumstances that can lead to inconsistent URLs being served in the page's mark-up, which may be interpreted differently by the client's browser.

Browser's will always interpret a URL beginning "http://" the same way - it's an absolute URL, so the destination will always resolve to the same thing. Make sure all your URLs to your main site begin "http://".

URLs beginning "www." (no http://) will be treated as relative URLs - i.e. if the page containing the URL is at http://www.google.com, you're essentially asking for http://www.google.com/YourUrl. You'll find this almost certainly isn't the behaviour you're looking for.

URLs beginning with a leading slash (/) will be treated as absolute on the current domain. For example "/Tools", within Google will result in a request to "http://www.google.com/Tools". If there's no leading slash, the browser will treated the URL as being relative to the page currently being viewed (i.e. a URL of "Tools" when you're viewing a page in the "en" folder would result in a request to "en/Tools".

I think this is where your problems are arising. For consistent behaviour, I find it's a good rule of thumb to ensure all URLs begin with a leading slash. If you want to ensure all your hyperlinks generated by your ASP code are correct, use the tilde (which ASP will replace with the path to the application root folder):

<asp:Hyperlink id="Test1" runat="server" NavigateUrl="~/Tools/Default.aspx">Tools</asp:Hyperlink>

This way, it doesn't matter where your page is in your site structure, whether you're using Cassini, a web site in IIS or a virtual directory in IIS - the URL will always resolve to the correct address.

If you want to output a URL that isn't a property of a server control, use the ResolveUrl method:

<a href="<%= ResolveUrl("~/Tools/Default.aspx")%>">Tools</a>

Hope this helps.

Paul Suart
Thats a ver complete response (+1), but all these URLs begin http:// which is as ABSOLUTE as you can get (or so I thought). However on the production server these are being changed.
Charlie