Skip to content

CookieService

Namespace: SlottyMedia.Backend.Services

This class is used to perform JSInterops to perform Read, Write, Exec operations on cookies. It uses the stored cookie.js file on client side (found in wwwroot/js)

public class CookieService : SlottyMedia.Backend.Services.Interfaces.ICookieService

Inheritance ObjectCookieService
Implements ICookieService

Constructors

CookieService(IJSRuntime)

Sets a singleton by using ctor injection

public CookieService(IJSRuntime jsRuntime)

Parameters

jsRuntime IJSRuntime

Methods

SetCookie(String, String, Int32)

Sets a cookie by taking a name, value and a expiration offset

public ValueTask SetCookie(string name, string value, int days)

Parameters

name String
Name of the cookie (key)

value String
Value of the cookie as string.

days Int32
Expiration offset in days. Standard value: 7 Days

Returns

ValueTask
Returns a value task

GetCookie(String)

Gets a cookie by name

public ValueTask<string> GetCookie(string name)

Parameters

name String
Name of the cookie f.e. "supabase.auth.token"

Returns

ValueTask<String>
Returns a value task of type string => output is the cookie value

RemoveCookie(String)

Removes a cookie by name

public ValueTask<string> RemoveCookie(string name)

Parameters

name String
Name of the cookie to identify it

Returns

ValueTask<String>
ValueTask of type string => output is the cookie value