Request.Url.ToString() returns the machine name ne

2019-08-15 06:03发布

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.

7条回答
放我归山
2楼-- · 2019-08-15 06:43

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>
查看更多
登录 后发表回答