Skip to content

CookieService

Implementation of ICookieService that writes and reads cookies through the current HttpContext. It sets the HttpOnly flag but not Secure or SameSite, and computes expiry from the server's local time.

Purpose

Context

  • Namespace: BolMiddleware.Services.CookieService
  • Assembly/package: BolMiddleware

Public members

Member Signature Purpose
Constructor CookieService(IHttpContextAccessor accessor) Receives the accessor used to reach the response and request cookies.
SetCookie void SetCookie(string name, string value, int timeout) Appends the cookie with expiry of local DateTime.Now plus the timeout.
SetCookieObject<T> void SetCookieObject<T>(string name, T value, int timeout) Serializes the object to JSON and sets it.
GetCookie string? GetCookie(string name) Returns the request cookie value.
GetCookieObject<T> T? GetCookieObject<T>(string name) Deserializes the request cookie.
DoesCookieExist bool DoesCookieExist(string name) Checks the request cookies.
DeleteCookie void DeleteCookie(string name) Deletes the cookie from the response.

Behavioral notes

Constraints and usage notes

  • Requires an active HttpContext.

Sources

  • src/BolMiddleware/Services/CookieService/CookieService.cs