【问题标题】:How to keep the session alive in dot net core 2.1如何在 dot net core 2.1 中保持会话活动
【发布时间】:2019-02-24 07:51:13
【问题描述】:
我们使用 dot net core 2.1,角度为 5。我们将用户 ID 和用户名等信息保存在会话中以进行身份验证。但问题是,一段时间后系统让用户注销。虽然,我们在那段时间提出了一些服务器端请求。有没有办法让会话保持活动状态,直到浏览器会话,无论用户是否在服务器端进行。即使用户发出服务器端请求,当在新选项卡中打开墨迹时,它也会要求再次登录。
【问题讨论】:
标签:
c#
angular
session
.net-core
【解决方案1】:
将凭据保存在本地存储中。下面是角码示例
import { Injectable } from '@angular/core';
import { TokenType } from './tokenResponseType';
@Injectable()
export class TokenManager {
private _tokenKey: string = 'bapp_key';
storeToken(tokenDetail: TokenType) {
localStorage.setItem(this._tokenKey, JSON.stringify(tokenDetail));
}
getToken() {
var tokenDetails = localStorage.getItem(this._tokenKey);
return JSON.parse(tokenDetails);
}
}