1

Seems like an obvious upgrade from regular localstorage, but I've only seen it used with Blazor.

I'm using ASP.NET Core 6.0 MVC.

Should I just put this in my program.cs?

builder.Services.AddScoped<ProtectedLocalStorage>();

1 Answer 1

0
  1. It is not possible to use ProtectedLocalStorage in an MVC project. It can only be used in Blazor server project.

Protected Browser Storage relies on ASP.NET Core Data Protection and is only supported for server-side Blazor apps.

https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-8.0&pivots=server#aspnet-core-protected-browser-storage

  1. You could use a cookie to persist the state in an MVC project, a minimal example here:
  • set cookie:

    Httpcontext.Response.Cookies.Append("key", "value", new CookieOptions(){......})

  • read cookie:

    HttpContext.Request.Cookies["key"]

Not the answer you're looking for? Browse other questions tagged or ask your own question.