天天看點

.Net Core WebApi實作跨域

.Net Core 需要引用一個包  Microsoft.AspNetCore.Cors

.Net Core WebApi實作跨域

讓接口實作跨域,需要配置兩個地方。

一、Startup.cs

這裡需要配置兩個地方

.Net Core WebApi實作跨域
.Net Core WebApi實作跨域
.Net Core WebApi實作跨域
.Net Core WebApi實作跨域
.Net Core WebApi實作跨域
.Net Core WebApi實作跨域
.Net Core WebApi實作跨域
.Net Core WebApi實作跨域

二、控制器 Controller

這裡可以直接在整個控制器上,加上 [EnableCors("any")] 标簽,也可以在單獨的 Action 上加上标簽。

.Net Core WebApi實作跨域

繼續閱讀