【发布时间】:2020-10-12 13:27:33
【问题描述】:
我在 IIS 中托管了一个 WebAPI,现在因为我需要从任何地方访问我的 API,我创建了一个 azure 代理,但每次我使用我的 UI 发出请求时,我都会收到以下错误:
startup.cs
配置服务
services.AddCors(options =>
{
options.AddDefaultPolicy(
builder =>
{
builder
.SetIsOriginAllowed((string v) => _ = true)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
配置
app.UseSerilogRequestLogging();
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
如果我在 IIS 所在的网络中运行我的前端代码,而不是调用代理调用 API 的本地主机,它就可以正常工作。
【问题讨论】:
标签: c# azure asp.net-core proxy asp.net-core-webapi