解决cookie问题

Test.EIImageViewer
hang 2023-10-10 11:14:50 +08:00
parent afb4e67eaa
commit d3f5bb64e2
4 changed files with 13 additions and 5 deletions

View File

@ -165,8 +165,8 @@ namespace IRaCIS.Api.Controllers
{ {
Expires = DateTime.Now.AddMonths(1), Expires = DateTime.Now.AddMonths(1),
HttpOnly = true, // 确保 cookie 只能通过 HTTP 访问 HttpOnly = true, // 确保 cookie 只能通过 HTTP 访问
SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None, // 设置 SameSite 属性 SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Unspecified, // 设置 SameSite 属性
Secure = true // 确保 cookie 只能通过 HTTPS 访问 Secure = false // 确保 cookie 只能通过 HTTPS 访问
}; };
HttpContext.Response.Cookies.Append("access_token", returnModel.Data.JWTStr, option); HttpContext.Response.Cookies.Append("access_token", returnModel.Data.JWTStr, option);

View File

@ -46,13 +46,13 @@
}, },
"applicationUrl": "http://localhost:6300" "applicationUrl": "http://localhost:6300"
}, },
"IRaCIS.CertificateApply": { "IRaCIS.Test-EIImageViewer": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "CertificateApply" "ASPNETCORE_ENVIRONMENT": "Test-EIImageViewer"
}, },
"applicationUrl": "http://localhost:6400" "applicationUrl": "http://localhost:6100"
} }
} }
} }

View File

@ -62,6 +62,7 @@ public class LimitUserRequestAuthorization : IAsyncAuthorizationFilter
//缓存中没有取到Token //缓存中没有取到Token
if (string.IsNullOrWhiteSpace(cacheUserToken)) if (string.IsNullOrWhiteSpace(cacheUserToken))
{ {
//设置当前用户最新Token //设置当前用户最新Token
await _provider.SetAsync(_userInfo.Id.ToString(), _userInfo.UserToken, TimeSpan.FromDays(7)); await _provider.SetAsync(_userInfo.Id.ToString(), _userInfo.UserToken, TimeSpan.FromDays(7));

View File

@ -186,6 +186,13 @@ namespace IRaCIS.Core.Domain.Share
{ {
return token; return token;
}
var cookieToken = _accessor?.HttpContext?.Request.Cookies["access_token"].ToString();
if (!string.IsNullOrWhiteSpace(cookieToken))
{
return cookieToken;
} }
return string.Empty; return string.Empty;