可能会多次询问此问题,但在线提供的解决方案对我不起作用.
在我们的项目中,我们使用WebMethod作为Asp.Net页面处理数据库,或者如果我这样说,我们有一个WebApi: -
HTTP://server/Pages/ApplicationData.aspx/GetApplicationLookups
现在我们有一个AspNet Core Angular Web应用程序,它调用了这个API
postgetGetApplicationLookups(url: string) {
var headers = new Headers();
headers.set('Accept', 'application/json; charset=utf-8');
headers.set('content-Type', 'application/json; charset=utf-8');
let data = {};
debugger;
return this.http.post(
url,
data,
{ headers: headers }
)
.map(this.handleSuccess)
.catch(this.handleError)
}
Run Code Online (Sandbox Code Playgroud)
如果我使用POSTMAN,这个POST调用工作正常: -
我使用以下代码修改了我的Startup.cs但我仍然得到相同的错误.
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin() //Fix API ISSUE
.AllowAnyMethod() //Fix API ISSUE
.AllowAnyHeader())); //Fix API ISSUE …Run Code Online (Sandbox Code Playgroud)