asp.net mvc获取绝对url(代理后面)

时间:2017-03-31 13:51:21

标签: c# asp.net asp.net-mvc

user --> internet --> server1 (iis proxy) --> server2 (hosting the website)

我正在尝试获取绝对网址。

当我们不使用代理时,下面的代码没有任何问题:

string fullUrl = Url.Action("Bar", "Foo", new RouteValueDictionary(new { id = pid, search = search }), Request.Url.Scheme);
string fullUrlEncoded = HttpUtility.UrlEncode(fullUrl);

但现在我收到了内部ip的绝对网址:

 http://192.168.0.3/Foo/Bar/5 

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我最终通过对appsettings中的url进行硬编码并将其添加到Chris Pratt建议的URL中。 我无法使用任何X-Forwarded-For标头,它已启用,但我没有收到该信息,因此无法使用它。