cookies未发送到客户端(静态Web应用程序)-Azure隔离功能
在随附的功能API(作为静态Web应用程序的一部分)中发送cookie作为对请求的响应时,未发送cookie。这仅发生在已部署的静态Web应用程序中 - 此问题在API函数的本地测试中不存在。
注意:我允许静态网站URL到Azure函数网站(CORS)
我的代码通过函数添加cookie:
{
HttpCookie cookie = new HttpCookie("serialno", "121345678");
cookie.Expires = DateTime.UtcNow.AddMonths(6);
cookie.SameSite = SameSite.Strict;
cookie.Path = "/";
cookie.HttpOnly = true;
HttpResponseData response = JsonResponseObject(req, loginResponse);
response.Cookies.Append(cookie);
return response;
}
internal static HttpResponseData JsonResponseObject(HttpRequestData req, object data)
{
var response = req.CreateResponse(System.Net.HttpStatusCode.OK);
response.Headers.Add("Content-Type", "application/json; charset=utf-8");
response.Body = ObjectToStream(data);
return response;
}
应该设置cookie,就像在本地测试API功能时它的工作原理一样。
When sending cookies as a response to a request in an included functions API (as part of a static web app), the cookies are not sent. This only occurs in a deployed static web app - this issue is not present in local testing of the API functions.
Notes: I have allowed static web site url to Azure functions website (CORS)
my code to add cookie through function:
{
HttpCookie cookie = new HttpCookie("serialno", "121345678");
cookie.Expires = DateTime.UtcNow.AddMonths(6);
cookie.SameSite = SameSite.Strict;
cookie.Path = "/";
cookie.HttpOnly = true;
HttpResponseData response = JsonResponseObject(req, loginResponse);
response.Cookies.Append(cookie);
return response;
}
internal static HttpResponseData JsonResponseObject(HttpRequestData req, object data)
{
var response = req.CreateResponse(System.Net.HttpStatusCode.OK);
response.Headers.Add("Content-Type", "application/json; charset=utf-8");
response.Body = ObjectToStream(data);
return response;
}
The cookie should be set, just like how it works when testing API functions locally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
响应对象不应作为代码的一部分创建,而是该函数的参数之一:
The response object shouldn't be created as a part of your code, it is one of the function's arguments: