Skip to content

AddProxySupport on .NET Framework not working with UseForwardedHeaders #174

@gumbarros

Description

@gumbarros

Describe the bug

As described in this issue , UseForwardedHeaders is not working, my website is displaying the subroute instead of the original request. I don't know if this is a SystemWebAdapter issue or YARP issue, please close this issue if it is 100% YARP related.

To Reproduce

Host in IIS a .NET Core website on www.site.com
Host in IIS a .NET Framework website on www.site.com/subapplication
Create a simple /Login route on .NET Framework website.
Add to .NET Framework website global.asax.vb:

   Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        RegisterSystemWebAdapters()
        
        Log.AddInfo("Sistema Dansales Web Iniciado...")
        
        AreaRegistration.RegisterAllAreas()
        RegisterRoutes(RouteTable.Routes)
        RegisterGlobalFilters(GlobalFilters.Filters)

        AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimsIdentity.DefaultNameClaimType
    End Sub

    Private Sub RegisterSystemWebAdapters()
        AddSystemWebAdapters() _
        .AddProxySupport(Sub(options)
                                               options.UseForwardedHeaders = True
                                       End Sub)
     End Sub

Go to www.site.com

Expected:
www.site.com/Login

Actual:
www.site.com/subapplication/Login

Technical Info

ASP.NET Framework Application:

  • Technologies and versions used: MVC + WebForms
  • .NET Framework Version: 4.8
  • Windows Version: Server 2012

ASP.NET Core Application:

  • Targeted .NET version: 6.0
  • .NET SDK version: 6.0

Why this is a migration problem

Because we have 100+ references using this getter:

        /// <summary>
        /// Captura a URL base do sistema
        /// </summary>
        /// <returns>URL</returns>
        /// <remarks>Lucio Pelinson 11-02-2009 / Gustavo Barros 24-08-2022</remarks>
        public static string PATH
        {
            get
            {
                var request = HttpContext.Current.Request;
                var helper = new UrlHelper(request.RequestContext);
                return string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, helper.Content("~"));
            }
        }

This causes many hyperlinks created with this getter to wrongly redirect only to the .NET Framework site instead of the Core one, but it don't happen when we use www.site.com/Login, only when we use www.site.com/subapplication/Login.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions