Search code examples
c#.netasp.net-coreproxyms-yarp

YARP - How to modify subapplication path?


My Scenario

I have the following IIS site:

www.site.com

Calling www.site.com/Login redirects correctly to the page in my subapplication, the browser bar shows www.site.com/Login.

But, calling www.site.com, redirects to www.site.com/subapplication/Login, it also works, but I want www.site.com to show www.site.com/Login in the browser bar.

IIS Structure

www.site.com is a .NET Core site with YARP

www.site.com/subapplication/Login is a .NET Framework site

appsettings.json

  "ReverseProxy": {
    "Routes": {
      "fallbackRoute": {
        "ClusterId": "fallbackCluster",
        "Order": "1",
        "Match": {
          "Path": "{**catch-all}"
        },
        "Transforms": [
          { "PathRemovePrefix": "/web" }
          { "RequestHeaderOriginalHost": "true" }
        ]
      }
    },
    "Clusters": {
      "fallbackCluster": {
        "Destinations": {
          "fallbackApp": {
            "Address": "https://dansaleswebdev.danone.com.br/dev/web/"
          }
        }
      }
    }
  }

What I want

www.site.com redirect to www.site.com/Login instead of www.site.com/subapplication/Login

I already tried to add the PathRemovePrefix transformation to remove /subapplication but it not worked.


Solution

  • Answered by Tratcher on GitHub.

    See #1548.

    You either need to change the framework app to generate the public urls, or you need to re-write the location header on the response.