我想从我的控制器启用 CORS 到 asp.net core 2 应用程序,因此在控制器中我添加如下属性:
[EnableCors(origins: "*", headers: "accept,content-type,origin,x-my-header", methods: "*")]
Run Code Online (Sandbox Code Playgroud)
但我在起源上遇到错误:
“EnableCorsAttribute”的最佳重载没有名为“origins”的参数
因此,我从元数据访问 EnableCorsAttribute 并找到了以下方法:
namespace Microsoft.AspNetCore.Cors
{
public class EnableCorsAttribute : Attribute, IEnableCorsAttribute
{
public EnableCorsAttribute(string policyName);
public string PolicyName { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
但假设它是这样的方法:
public EnableCorsAttribute(string origins, string headers, string methods);
Run Code Online (Sandbox Code Playgroud)
为什么我没有?我需要安装一些东西吗?我是 Asp.Net Core 的新手,我不明白为什么该方法不在我的 api 中。问候