Url.Link() in ASP.NET app behind reverse proxy returns wrong hostport - Stack Overflow

I have a ASP.NET Web API controller which inherits from a custom class which in turn inherits from Syst

I have a ASP.NET Web API controller which inherits from a custom class which in turn inherits from System.Web.Http.ApiController. In one of my actions, I return a URL to another action of the same controller by using Url.Link().

Recently, we introduced a new version of the application in .NET 8. But we keep the legacy app and forward the requests to it by using a reverse proxy (YARP in our case). During this, we changed the port for the legacy app in local IIS to something like 12345. The new app is hosted on a Docker container and the routing is done by using Ingress.

This change, however, adds the port number to the host when the request is received by the legacy app. This causes a CORS policy error when the client tries to call the returned URL.

So, I'm trying to figure out where I can fix the host for the returned URL.

What I've already tried

  • Adding proxy_set_header X-Forwarded-Host to nginx configuration. It didn't seem to make any change.
  • Setting HttpContext.Current.Request.ServerVariables["HTTP_HOST"] in Application_BeginRequest in Global.asax.cs (in legacy app). When I debug and step into my action, I can see that Request.Headers.Host is changed accordingly, but Request.RequestUri still showing the old host (with port) and so does Url.Link().

Anything I might have missed? Or any other subtle solution?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300284a4621395.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信