在Azure函数中设置cors标头 [英] Setting cors headers in Azure function

查看:153
本文介绍了在Azure函数中设置cors标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Azure函数中,我尝试设置cors标头:

In my Azure function, I try to set cors headers:

var response = req.CreateResponse(HttpStatusCode.OK);
response.Content = new ObjectContent<List<RecordEntity>>(data, new JsonMediaTypeFormatter(), "application/json");

response.Headers.Add("Access-Control-Allow-Origin", "*");
response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT");
response.Headers.Add("Access-Control-Allow-Headers", "*");
response.Headers.Add("Access-Control-Allow-Credentials", "true");

return response;

但是,这些标头均未在http响应中到达客户端,而是从响应中剥离了.

However, none of these headers get to the client in the http response, they are stripped from the response.

我想还有其他设置cors标头的方法,但是找不到它的工作原理.

I suppose there is some other way of setting the cors headers, but cannot find how it works.

推荐答案

Azure门户中的CORS设置位于Function App-> Platform Features下.

The CORS setting in the Azure portal is under Function App -> Platform Features.

有用的是,从列表中删除了所有允许的来源(如链接 https://blogs.msdn.microsoft.com/benjaminperkins/2017/04/12/azure-functions-access-control-allow-credentials -with-cors/).

What helped was to delete all Allowed origins from the list (as described in the link https://blogs.msdn.microsoft.com/benjaminperkins/2017/04/12/azure-functions-access-control-allow-credentials-with-cors/).

当允许的来源"列表为空时,最后,从http响应中的Azure函数向客户端发送了手动设置的cors标头,并且未剥离.

When the list of Allowed origins is empty, then finally the manually set cors headers are sent from Azure function in the http response to the client and are not stripped.

这篇关于在Azure函数中设置cors标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆