Daniel
Daniel

Reputation: 9534

asp.net-core - Set response's virtual path with middleware

Setup

Problem

My middleware correctly routes the request to the page. Based on the headers, requests to https://second-domain.com/some/path/PageX correctly retrieve the resource at https://first-domain.com/PageX.

However, PageX's URLs which use the ASP.NET root path character (~) are resolving to / so then the client tries to access resources at https://second-domain.com/ which don't exist.

For example, if PageX.cshtml had a <img src="~/myImage.png> tag, the client's browser will try to retrieve resource https://second-domain.com/myImage.png instead of https://second-domain.com/some/path/myImage.png

Question

Is there a way to manipulate the request and/or response with ASP.NET-Core middleware such that the ASP.NET root path (~) is resolved dynamically?

In other words, I'm trying to set a virtual path dynamically without using infrastructure-defined virtual paths via IIS/Azure.

Upvotes: 1

Views: 884

Answers (1)

Daniel
Daniel

Reputation: 9534

This can be accomplished by setting context.Request.PathBase from the middleware.

Upvotes: 1

Related Questions