gpt4 book ai didi

c# - PreFlight 请求 404 未找到 .net web api;对预检请求的响应未通过访问控制检查 : it does not have http ok status

转载 作者:太空狗 更新时间:2023-10-30 00:47:49 24 4
gpt4 key购买 nike

<分区>

所以我想在我的 .net Web API 上启用 CORS,但客户端应用程序不断收到 404 选项请求和第二个错误:

Has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: it does not have http ok status

我按照微软官网的介绍一步一步来,还是不行。

public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Added this line to my WebApiConfig.cs file
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}


I also tried it by adding the headers in the Web.config in the httpProtocol tag file like so:

<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="*" />
<add name="Access-Control-Allow-Methods" value="*" />
</customHeaders>
</httpProtocol>

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com