A static HTML file is displayed (as raw) in a simple view.
Problem is that urls in the html are not mapped "correctly" (in my case), because the test site is hosted in a sub folder.
Dev-Site:
https://localhost:43444/Page1
Test-Site:
https://www.domain.com/Preview/Page1
Environment:
ASP.net Core 3.1 MVC
It's clear that the image on the test site referes to
https://www.domain.com/Images/Page1.png.
And (of course) changing the src to "~/Images/Page1.png" is not evaluated.
There is a solution from Microsoft but which path do I have to set here?
What I have tried:
wwwroot/pages/Page1.htm:
<img src='/Images/Page1.png' />
<img src='~/Images/Page1.png' />
Pages/Page1.cshtml:
@{
var htmlContent = System.IO.File.ReadAllText(@$"wwwroot\pages\Page1.htm");
}
@Html.Raw(htmlContent)
Microsoft's approach:
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath, env.ContentRootPath)),
RequestPath = "~/"
});