此博客中的代码
后端框架为Asp .net core,前端框架为React,Http请求发送方式为 Fecth
需要两步:
- 在后端设置 Access-Control-Allow-Credentials 为true
在设置 Access-Control-Allow-Credentials 需要注意的是 需要将 Access-Control-Allow-Origin 设置为指定源,AllowAny情况无法设置 Credentials 为true
2. 设置请求头中的 credentials 为true,在anixos中该字段名为 withCredentials 设为true即可,在Fetch中该字段名为 credentials 需设置为 include