我如何将cookie设置为安全的.NET Core?

问题描述 投票:0回答:1

我在使用Identity Server 4时遇到问题。这是一个常见问题,需要SameSite = None和安全cookie。当我设法将SameSite设置为None时,我没有将cookie设置为安全。

我尝试过在线搜索,但找不到任何完整的解决方案。因为我没有经验,所以我也需要在哪里使用那部分代码的信息。

我正在使用ASP.NET Core 3.1。

谢谢

security asp.net-core identityserver4 asp.net-core-3.0 asp.net-core-3.1
1个回答
0
投票

您可以这样设置cookie设置

services.AddIdentityServer()
.AddInMemoryClients(Clients.Get())
.AddInMemoryIdentityResources(Resources.GetIdentityResources())
.AddInMemoryApiResources(Resources.GetApiResources())
.AddDeveloperSigningCredential()
.AddTestUsers(TestUsers.Users);

services.AddAuthentication("MyCookie")
    .AddCookie("MyCookie", options =>
    {
        options.ExpireTimeSpan = ...;
    });

有关更多信息,请阅读Cookie authentication

© www.soinside.com 2019 - 2024. All rights reserved.