重新启动网站后,在Debian 8上托管的.NET Core 2.2 Web应用程序“丢失”会话

时间:2019-05-17 02:58:05

标签: session .net-core

如果我登录到我的网站,然后进行了部署(在其中重新启动Supervisor服务),则我已退出我的网站,但该会话仍存在于SQL Server中。

这是我的网站主管模板

[program:{Program}]
command=/usr/bin/dotnet {Directory}{Project}.dll --server.urls:http://*: 
{Port}
directory={Directory}
autostart=true
autorestart=true
stderr_logfile=/var/log/www/{Build}/{Project}.err.log
stdout_logfile=/var/log/www/{Build}/{Project}.out.log
environment=ASPNETCORE_ENVIRONMENT={Environment}
user=www-data
stopsignal=INT

在这里我在Startup.cs中设置Cookie /会话

        services.AddDistributedSqlServerCache(options =>
        {
            options.DefaultSlidingExpiration = TimeSpan.FromDays(365 * 50);
            options.ConnectionString = AppHttpContext.Configuration.GetSection("ConnectionStrings")["DiFractal.Workout"];
            options.SchemaName = "dbo";
            options.TableName = "Session";
        });

        services.AddSession(options =>
        {
            options.IdleTimeout = TimeSpan.FromDays(365 * 50);
            options.Cookie.MaxAge = TimeSpan.FromDays(365 * 50);
        });
        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(options =>
        {
            options.SlidingExpiration = true;
            options.ExpireTimeSpan = TimeSpan.FromDays(365 * 50);
            options.Cookie.Expiration = TimeSpan.FromDays(365 * 50);
        });

这是SQL Server中的会话表

CREATE TABLE [dbo].[Session](
[Id] [nvarchar](900) NOT NULL,
[Value] [varbinary](max) NOT NULL,
[ExpiresAtTime] [datetimeoffset](7) NOT NULL,
[SlidingExpirationInSeconds] [bigint] NULL,
[AbsoluteExpiration] [datetimeoffset](7) NULL,
 CONSTRAINT [PK_Session_Id] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

必须具有某种过程方面,这在网站重新启动时会丢失

0 个答案:

没有答案