views:

648

answers:

6

When I deployed my application on the server I faced this issue:

Request.Url.ToString(); returns the machine name instead of the domain name.

For example:

Instead of returning http://www.domainName.com/default.aspx it returns http://appserver-01/default.aspx.

Note: Everything was OK before the deployment.

A: 

We had a similar issue. In our case it was - what was the very first request that hit the site (after IISReset). If you hit it with this URL: http://appserver-01/default.aspx then it will keep using it.

Try the following: 1. IISReset 2. Request this URL: http://www.domainNmae.com/default.aspx 3. see if the issue is resolved

DmitryK
still the same issue exists.
Khaled Musaied
+1  A: 

You could also look into the myriad other ways to resolve the url or domain. For example, Request.RawUrl typically returns whatever was typed into the address bar, etc.

tsilb
I can resolve the issue with any workaround but it was working before deployment!!
Khaled Musaied
MSDN claims that RawUrl does not contain domain name. "The raw URL is defined as the part of the URL following the domain information. In the URL string http://www.contoso.com/articles/recent.aspx, the raw URL is /articles/recent.aspx. The raw URL includes the query string, if present."
Kamil Szot
+1  A: 

Well, digging in with Reflector, it seems to me that the Uri object contained in Request.Url is definitely built from the information that comes in from the request headers.

In light of that, I's suspect that maybe the requests coming in aren't what you think they are. Try having a look at the Raw headers in the requests coming into your server. I'd use a packet sniffer for this, I'd bet they reflect the problem you're seeing. If so, the problem isn't on your web server, it's somewhere in front of that.

Do you have any forwarding set up somewhere that could be causing this issue? Like http forwarding done by some sort of domain controller? Do you have any custom HttpHandlers that are massaging the request before handing them off? If you do, I'd look there. If you don't think you do, ask your Network Admin (if you have one) just to be safe.

All of this is a stab in the dark as I don't know your whole set up. But it's my best guess.

Good luck!

blesh
+4  A: 

It sounds like it could be one or more of the following:

  1. your server is sitting behind a firewall and/or load balancer that are stripping the Host: header from the request.

  2. Check the IIS configuration - the binding list should include both domainName.com and www.domainName.com instead of being blank (default site).

  3. Are you making the requests from inside or outside your company network? The network administrator may have configured internal DNS differently than the external DNS.

Drop this code as ServerVariables.aspx somewhere on your site (temporarily: it exposes server configuration info) and it will dump the request headers:

<%@ Page Language="C#" Theme="" %>
<html>
<head>
<title>Server Variables</title>
<style>
thead th {border-bottom: 2px solid  #000000; padding: 2px 8px; font-size: 130%; text-align: left;}
tbody td {border-bottom: 1px dotted #999999; padding: 2px 8px;}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
 <thead>
  <tr>
   <th>Server Variable</th>
   <th>Value</th>
  </tr>
 </thead>
 <tbody><%
    foreach (string name in Request.ServerVariables)
    {
%>
  <tr>
   <td><pre><%= name %></pre></td>
   <td><pre><%= Request.ServerVariables[name] %>&nbsp;</pre></td>
  </tr><%
    }
%>
 </tbody>
</table>
</body>
</html>
devstuff
A: 

What value returns this calls?

Request.ServerVariables("SERVER_NAME");
Request.ServerVariables("HTTP_HOST");
Rodrigo
+1  A: 

Host header (which is where Request.Url gets the domain name) is rewritten with the machine that proxies traffic from outside.

Original domain lands in header X-Forwarded-Host. You should read it from there.

You can also force proxy to preserve host header. If your proxy is apache mod_proxy you can use directive:

ProxyPreserveHost On

Kamil Szot