Request.Url.ToString()返回嵌套域的机器名

Kha*_*ied 1 asp.net deployment

当我在服务器上部署我的应用程序时,我遇到了这个问题:

Request.Url.ToString(); 返回计算机名称而不是域名.

例如:

而不是返回http://www.domainName.com/default.aspx它返回http://appserver-01/default.aspx.

注意: 部署之前一切正常.

dev*_*uff 5

听起来它可能是以下一种或多种:

  1. 您的服务器位于Host:从请求中剥离标头的防火墙和/或负载平衡器后面.

  2. 检查IIS配置 - 绑定列表应包括两者domainName.comwww.domainName.com不是空白(默认站点).

  3. 您是在公司网络内部还是外部提出请求?网络管理员可能已配置内部DNS与外部DNS不同.

将此代码删除ServerVariables.aspx到您站点上的某个位置(暂时:它公开服务器配置信息),它将转储请求标头:

<%@ 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>
Run Code Online (Sandbox Code Playgroud)