[英]Session Management in asp.net core 3.1
我正在使用 asp.net core 3.1 MVC 登錄系統,我正在使用 (AspNetCore.Identity) 包。 當我在本地主機上運行應用程序時,它工作正常。 但是一旦我將其上傳到服務器,問題就會再次出現。 用戶無法保持登錄狀態。 我試圖在此基礎上配置會話管理。 在啟動文件中,我使用代碼:
public void ConfigureServices(IServiceCollection services)
{
//Session Configuration
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(20);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
services.AddControllersWithViews();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//TODO: Change Environment in launchSettings.json to Production before publishing the application.
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseStatusCodePagesWithReExecute("/Error/{0}");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
//Use Session
app.UseResponseCaching();
app.UseSession();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
在控制器中,我使用以下內容:
private readonly IHttpContextAccessor _httpContextAccessor;
private const string SessionUser = "_User";
private const string SessionRole = "_Role";
用戶現在可以登錄,但問題仍然存在,系統將用戶注銷。
請在這方面提供幫助,並在此先感謝您。
請檢查令牌信息JWT您可以復制粘貼您的令牌,並找出您的門戶的到期時間和聲明信息以管理您的會話。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.