URLs requested via Http on the server must be absolute Only in IE11 #271

Closed
opened 2025-08-09 17:15:39 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @NeilIrvingMacc on 12/12/2017

Hi,

I have created a new Angular4 project from the latest template via VS2017 and have created my first page. The page works fine in Chrome and Edge but in IE I get the error 'URLs requested via Http on the server must be absolute' during server pre rendering.

The piece of code that fails is a call to get some data from a WebApi controller:

this.http.post('/api/Content/GetBasicContentByID',
body, options).subscribe(
res => {
this.extractData(res)
},
err => { this.handleError(err) });

I did some Googling on this and found this:

https://stackoverflow.com/questions/43300257/system-exception-call-to-node-module-failed-with-error-error-urls-requested-v

and also on here an old issue here which is the same:

https://github.com/aspnet/JavaScriptServices/issues/989

Issue 989 above talks about using BASE_URL now which I can see in my app.module.browser.ts:

providers: [
{ provide: 'BASE_URL', useFactory: getBaseUrl }
]

export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
}

My question is how do I call the getBaseUrl function above from my typescript code behind page / the code at the top of the post

Thanks

Neil

*Originally created by @NeilIrvingMacc on 12/12/2017* Hi, I have created a new Angular4 project from the latest template via VS2017 and have created my first page. The page works fine in Chrome and Edge but in IE I get the error 'URLs requested via Http on the server must be absolute' during server pre rendering. The piece of code that fails is a call to get some data from a WebApi controller: this.http.post('/api/Content/GetBasicContentByID', body, options).subscribe( res => { this.extractData(res) }, err => { this.handleError(err) }); I did some Googling on this and found this: https://stackoverflow.com/questions/43300257/system-exception-call-to-node-module-failed-with-error-error-urls-requested-v and also on here an old issue here which is the same: https://github.com/aspnet/JavaScriptServices/issues/989 Issue 989 above talks about using BASE_URL now which I can see in my app.module.browser.ts: providers: [ { provide: 'BASE_URL', useFactory: getBaseUrl } ] export function getBaseUrl() { return document.getElementsByTagName('base')[0].href; } My question is how do I call the getBaseUrl function above from my typescript code behind page / the code at the top of the post Thanks Neil
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#271
No description provided.