I have two ASP .Core MVC applications that are hosted under the same url.
I’ve managed to separate them with Nginx so that a certain path goes to app-2
, while the rest goes to app-1
:
http://host
-> app-1
http://host/setup
-> app-2
My problem comes when the user connects to app-2
, as the application still thinks it’s app-root is http://host
.
This leads to the client encountering a 404 when for example style sheets are downloaded, since app-2.css
exists under http://host/setup/css
but the application searches in http://host/css
.
The "include"-lines in the .cshtml
file in app-2
look like this:
<link rel="stylesheet" type="text/css" href="@Url.Content("~/css/app-2.css")" asp-append-version="true" />
Is there some way of "overriding" or telling app-2
that ~
should refer to <host>/setup/css/
instead of <host>/css/
?
I really don’t want to hardcode it in case the url changes at some point.
2
Answers
After many hours of searching I found no way of altering the application root for the entire webserver.
What I ended up doing instead was create class
PathHelper
with options and added it toStartup.cs
:I then used it in the
.cshtml
files like this:I think the easiest way is to include the
base
tag in pages coming from ‘app-2’.Try it like this:
Now your relative links are sent to ‘app-2’.