Skip to content

Host header is changed too late when using UseHostHeaderForRequestUrl #156

@khellang

Description

@khellang

Describe the bug

When running the backend ASP.NET app with the following app setting:

<add key="aspnet:UseHostHeaderForRequestUrl" value="true" />

The Host header from the backend app will be used to build Request.Url instead of the forwarded proxy host.

This seems to be because the Host header from X-Forwarded-Host is set too late in the pipeline and that Request.Url has already been calculated.

To Reproduce

Add the following app setting to the backend ASP.NET app:

<add key="aspnet:UseHostHeaderForRequestUrl" value="true" />

Inspect Request.Url in the app. It should show the host of the backend app, not the proxy.

Further technical details

ASP.NET Framework Application:

  • Technologies and versions used (i.e. MVC/WebForms/etc): MVC, WebForms, WebAPI
  • .NET Framework Version: 4.8.4515.0
  • IIS Version: 10.0.19041.320
  • Windows Version: 21H2

ASP.NET Core Application:

  • Targeted .NET version: net6.0
  • .NET SDK version: 6.0.400

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions