gpt4 book ai didi

c# - 在 ASP.NET Core 2 中获取 "SessionOptions.CookieName is obsolete"

转载 作者:行者123 更新时间:2023-11-30 14:06:43 24 4
gpt4 key购买 nike

我最近升级到 ASP.NET Core 2。该网站使用 session ,但升级后我得到:

"SessionOptions.CookieName' is obsolete: 'This property is obsolete and will be removed in a future version. The recommended alternative is Cookie.Name."

新的session实现方式是什么?

当前实现,Startup.cs(ConfigureServices):

services.AddSession(options =>
{
options.CookieName = ".Smokers.Session";
options.IdleTimeout = TimeSpan.FromHours(2);
});

Startup.cs(配置):

.
.
.
app.UseSession();

最佳答案

What is the new way to implement session?

从阅读错误信息...

"SessionOptions.CookieName' is obsolete: 'This property is obsolete and will be removed in a future version. The recommended alternative is Cookie.Name."

...您似乎想使用 Cookie.Name

Unifying API for configuring cookie settings

public void ConfigureServices(ServiceCollection services)
{
services.AddSession(options =>
{
// obsolete
options.CookieName = "SessionCookie";
options.CookieDomain = "contoso.com";
options.CookiePath = "/";
options.CookieHttpOnly = true;
options.CookieSecure = CookieSecurePolicy.Always;
// new API
options.Cookie.Name = "SessionCookie";
options.Cookie.Domain = "contoso.com";
options.Cookie.Path = "/";
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
});
}

关于c# - 在 ASP.NET Core 2 中获取 "SessionOptions.CookieName is obsolete",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45766941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com