【发布时间】:2018-07-05 15:10:26
【问题描述】:
我在允许 cors 时遇到了一些问题。我已经这样设置server side:
app.UseCors(builder => builder.WithOrigins("http://localhost:4200/").AllowAnyHeader());
startup 类的configure 方法内部
当我的网络 API 被点击时,它会很好地返回数据。
但是,问题似乎出在 Angular 上,因为我收到以下错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
这是我的 Angular Web api 调用
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';;
@Injectable()
export class ProfileService {
private baseUrl = 'api/profile/';
constructor(private http: HttpClient) { }
getLookups(step: number) {
return this.http.get('http://localhost:51658/' + this.baseUrl + 'lookups/' + step)
}
}
【问题讨论】:
-
您的 ASP.NET Core 应用程序中是否有任何异常?如果是,请注意异常将CLEAN CORS 中间件设置的任何 CORS 标头
-
@Tseng,非常感谢 - 有趣的花絮。您能否详细说明或指出有关此的任何文档?我想我们一直在遇到这个问题
标签: angular asp.net-core cors