A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
the Blazor client app project can not reference the server app project. the client app runs in the browser as a WASM and can not access any server components.
if you use the new Blazor Web App project structure, and the server project references the Blazor client project, you can use Server pre-render to read the cookie and write to presistant state:
https://learn.microsoft.com/en-us/aspnet/core/blazor/components/prerender?view=aspnetcore-9.0
this works by:
- the server loads the Blazor code via dll
- the server run the Blazor app pre-render event. the pre-render can access server DI services
- the server renders the pre-render output (including any save state)
- the browser loads the page
- the browser js load the Blazor WASM app
- the browser WASM app uses jsinterop to load the state data.
if not using pre-render, then the hosting page, can render the cookie values as a javascript variable, and the Blazor App can use jsinterop to read the values.
if this is a pure Blazor app, you might use local storage rather than a cookie, but pre-render cannot access local storage.
note: neither Blazor Server or Blazor WASM can write a cookie as there is no response to write the cookie to (the request has completed before the Blazor app loads).