admin管理员组

文章数量:1418870

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?

本文标签: UrlLink() in ASPNET app behind reverse proxy returns wrong hostportStack Overflow