如何从 NextJs 访问 HttpContext.Session

时间:2021-04-13 09:07:52

标签: asp.net-core axios next.js

我使用 Nextjs 作为前端,使用 Asp.Net 核心作为后端 (API)。我使用 JWT 身份验证从 Next Js 使用 axios 访问端点。我还在后端设置会话来存储用户数据。问题是 HttpContext.Session 始终为空。以下是我使用的代码示例:

axios.post(`https://localhost:44301/Home/GetValues`, { },       

    {
        headers: {
            'Authorization': `Bearer ${token}`,
            'Content-Type': 'application/json'

        },
        withCredentials: true
    }
)
    .then(res => {
        console.log("Values", res.data);          

    })
    .catch(err => console.log(err));

使用 Postman 可以访问 HttpContext.Session。这意味着 Nextjs 不会发送由 Asp.net 核心设置的会话 cookie。

0 个答案:

没有答案
相关问题