Angular 2错误:未捕获(在承诺中):状态响应:URL为0:null

时间:2017-05-29 11:06:17

标签: asp.net angular typescript asp.net-core

我的申请是ASP.NET Core 1.0 Web API。 Iam使用Angular 2typescript开发前端。

如果我在完全加载Google Chrome之前刷新网站,一切正常,但如果我在Mozilla Firefox上做同样的事情,我会收到以下错误消息:

[error.service] An error occured: Object { _body: error, status: 0, ok: false, statusText: "", headers: Object, type: 3, url: null }  app.e9e4671abf55fe5a53fc.js:936:46167

s</ConsoleLogger.prototype.error TheNameOfMyWebSite.net/js/app.e9e4671abf55fe5a53fc.js:936:46167
u</ErrorService.prototype.handleError TheNameOfMyWebSite.net/js/app.e9e4671abf55fe5a53fc.js:936:39646
u</CustomHttp.prototype.request/< TheNameOfMyWebSite.net/js/app.e9e4671abf55fe5a53fc.js:936:38047
a</CatchSubscriber.prototype.error TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:543:27790
a TheNameOfMyWebSite.js:311:808
[264]/</</</o</ZoneDelegate.prototype.invokeTask TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:8316
onInvokeTask TheNameOfMyWebSite.js:176:9452
[264]/</</</o</ZoneDelegate.prototype.invokeTask TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:8229
[264]/</</</n</Zone.prototype.runTask TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:3362
ZoneTask/this.invoke TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:9349


ERROR Error: Uncaught (in promise): Response with status: 0  for URL: null
Stack-Trace:
resolvePromise@TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:1180
resolvePromise@TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:796
scheduleResolveOrReject/<TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:1803
[264]/</</</o</ZoneDelegate.prototype.invokeTask@TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:8316
onInvokeTask@TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:9452
[264]/</</</o</ZoneDelegate.prototype.invokeTask@TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:8229
[264]/</</</n</Zone.prototype.runTask@TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:3362
drainMicroTaskQueue@TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:367
ZoneTask/this.invoke@TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:9396

defaultErrorLogger TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:8:473
ee</ErrorHandler.prototype.handleError TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:162:273
next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:14602
Qe</EventEmitter.prototype.subscribe/i< TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:6258
c</SafeSubscriber.prototype.__tryOrUnsub TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:3724
c</SafeSubscriber.prototype.next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:2960
u</Subscriber.prototype._next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:1927
u</Subscriber.prototype.nextTheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:1574
p</Subject.prototype.next TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:211:6849
Qe</EventEmitter.prototype.emit TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:6006
Xe</NgZone.prototype.triggerError TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:10237
onHandleError TheNameOfMyWebSite.net/js/vendor.e9e4671abf55fe5a53fc.js:176:9812
[264]/</</</o</ZoneDelegate.prototype.handleError TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:7683
[264]/</</</n</Zone.prototype.runGuarded TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:2951
[264]/</</</n.microtaskDrainDone/< TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:2461
[264]/</</</n.microtaskDrainDone TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:57:2430
drainMicroTaskQueue TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:477
ZoneTask/this.invoke TheNameOfMyWebSite.net/js/polyfills.e9e4671abf55fe5a53fc.js:50:9396 

但网站更新很好,除了我收到的错误外,一切都运行得很好。

我只发现了this answer帖子,这个人有类似的问题。

Stackoverflow上的另一个人也有this,但由于我没有使用similar problem,因为前端和后端在同一个域上运行,这对我来说不起作用。

此错误消息是什么意思?我做错了什么?

1 个答案:

答案 0 :(得分:0)

这看起来像是一个CORS问题。

  

跨域资源共享(CORS)是一种机制,允许从提供第一个资源的域外的另一个域请求网页上的受限资源(例如字体)。

详细了解here

基本上,您的Angular2应用程序托管在除您正在呼叫的API之外的其他服务器上。

由于您使用的是ASP.NET Core 1.0 Web API,我建议您仔细阅读Microsoft的Enabling Cross-Origin Requests (CORS)文档。