MMIX.Blazor.Cookies
1.0.4
dotnet add package MMIX.Blazor.Cookies --version 1.0.4
NuGet\Install-Package MMIX.Blazor.Cookies -Version 1.0.4
<PackageReference Include="MMIX.Blazor.Cookies" Version="1.0.4" />
<PackageVersion Include="MMIX.Blazor.Cookies" Version="1.0.4" />
<PackageReference Include="MMIX.Blazor.Cookies" />
paket add MMIX.Blazor.Cookies --version 1.0.4
#r "nuget: MMIX.Blazor.Cookies, 1.0.4"
#:package MMIX.Blazor.Cookies@1.0.4
#addin nuget:?package=MMIX.Blazor.Cookies&version=1.0.4
#tool nuget:?package=MMIX.Blazor.Cookies&version=1.0.4
MMIX.Blazor.Cookies
ASP.NET-compatible cookie management for Blazor.
MMIX.Blazor.Cookies is a modern, .NET 8+ library for easy browser cookie management across all Blazor render modes. It is a highly modified fork of Bitzart's Blazor.Cookies project, optimized for better ASP.NET integration and full prerendering support.
- Supports all Blazor United (.NET 8+) render modes: Static SSR, Interactive Server, Interactive WebAssembly, and Interactive Auto
- Compatible with ASP.NET and Blazor Web App projects
- Simple, dependency-injection-friendly API: inject
ICookieServiceand manage cookies anywhere
Installation
Install the following package in your Blazor Server and/or Blazor Client project:
dotnet add package MMIX.Blazor.Cookies
Add this line to your Server and/or Client project program.cs:
builder.Services.AddCookieService();
Usage
Injecting the ICookieService in a class:
using MMIX.Blazor.Cookies;
public class Foo
{
private readonly ICookieService _cookieService;
public Foo(ICookieService cookieService)
{
_cookieService = cookieService;
}
public async Task SetCookie()
{
await _cookieService.SetAsync("hello", "world");
}
}
Injecting the ICookieService in a Blazor component:
@using MMIX.Blazor.Cookies
@inject ICookieService CookieService
@code {
public async Task SetCookie() {
await CookieService.SetAsync("hello", "world");
}
}
Supported Methods
The ICookieService interface provides the following methods:
Reading Cookies
// Retrieves a cookei by its name
Task<Cookie?> GetAsync(string name);
// Retrieves all cookies
Task<IEnumerable<Cookie>> GetAllAsync();
Setting Cookies
// Sets a cookie
Task SetAsync(string name, string value, CancellationToken cancellationToken = default);
// Sets a cookie with an expriation date
Task SetAsync(string name, string value, DateTime expires, CancellationToken cancellationToken = default);
// Sets a cookie with a CookieOptions object
Task SetAsync(string name, string value, CookieOptions cookieOptions, CancellationToken cancellationToken = default);
// Sets a cookie using a Cookie object
Task SetAsync(Cookie cookie, CancellationToken cancellationToken = default);
// Sets multiple cookies using a Cookie IEnumerable
Task SetAsync(IEnumerable<Cookie> cookies, CancellationToken cancellationToken = default);
Removing Cookies
// Removes a cookie by its name
Task RemoveAsync(string name, CancellationToken cancellationToken = default);
// Removes all cookies
public Task RemoveAllAsync(CancellationToken cancellationToken);
License
Credits to the original developers
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Microsoft.AspNetCore.Http.Features (>= 3.1.32)
- Microsoft.JSInterop (>= 8.0.22)
-
net9.0
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Microsoft.AspNetCore.Http.Features (>= 3.1.32)
- Microsoft.JSInterop (>= 9.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Fixed major bug that will fail install because it looks for non-existant MMIX.Blazor.Cookies.Patches package