Reputation: 5290
I have an Aurelia app running under Asp MVC Core 1.0. The app uses HttpClient to call controller actions, which return json data. The Home controller contains all the actions, and I configure the HttpClient like so:
http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('Home/');
});
When running the application in Visual Studio, everything works. It's hosted on localhost:55475
, and when I call this.http.fetch('GetData')
, it makes a request to localhost:55475/Home/GetData
.
The problem comes when I deploy to IIS. The application is deployed as a web application under the default web site, so the root url is server.org/MyApp
. The application starts up fine, but when I make the call this.http.fetch('GetData')
, it requests from server.org/Home/GetData
instead of server.org/MyApp/Home/GetData
, which obviously results in a 404.
Why is my fetch request ignoring MyApp
? I thought not having a leading slash on my .withBaseUrl
would make the url relative, but apparently not?
Upvotes: 0
Views: 470
Reputation: 747
The solution I found was down to the URL I put into the browser address bar... in your case, does it start to work if you browse to server.org/MyApp/ rather than to server.org/MyApp (note the extra slash)? That worked for me.
So the overall fix I needed to put in place was to have a base
element at the top of the page hosting Aurelia that set the base URL with a trailing slash e.g.
<base href="/MyApp/" />
Which I added using ASP.Net Core with this line in my index.cshtml file:
<base href="@this.Url.Content("~")/" />
That or you could redirect your users to the full URL using a 302 response.
Upvotes: 1