33 lines
812 B
C#
33 lines
812 B
C#
namespace ChatApi
|
|
{
|
|
public class SessionIdStore
|
|
{
|
|
HttpContext _context;
|
|
|
|
public SessionIdStore(HttpContext httpContext)
|
|
{
|
|
_context = httpContext;
|
|
}
|
|
|
|
public string GetSessionId()
|
|
{
|
|
var sessionId = _context.Request.Cookies["ChatSessionId"];
|
|
|
|
if (sessionId == null)
|
|
{
|
|
sessionId = Guid.NewGuid().ToString("N");
|
|
_context.Response.Cookies.Append("ChatSessionId", sessionId, new CookieOptions
|
|
{
|
|
Expires = DateTimeOffset.Now.AddMonths(12),
|
|
HttpOnly = true,
|
|
SameSite = SameSiteMode.None,
|
|
Secure = true
|
|
});
|
|
}
|
|
|
|
|
|
return sessionId;
|
|
}
|
|
}
|
|
}
|