tsuyoshi 羽鳥
tsuyoshi 羽鳥
CC#
Created by TJ3046 on 4/17/2025 in #help
[SOLVED] Accessing HttpOnly Cookies during Prerendering
Where are you from?
27 replies
CC#
Created by TJ3046 on 4/17/2025 in #help
[SOLVED] Accessing HttpOnly Cookies during Prerendering
I think so
27 replies
CC#
Created by TJ3046 on 4/17/2025 in #help
[SOLVED] Accessing HttpOnly Cookies during Prerendering
So are you a developer?
27 replies
CC#
Created by TJ3046 on 4/17/2025 in #help
[SOLVED] Accessing HttpOnly Cookies during Prerendering
Also, be sure that the cookie isn’t marked as HttpOnly if you need to read it in JavaScript (like when fetching data client-side after hydration).
27 replies
CC#
Created by TJ3046 on 4/17/2025 in #help
[SOLVED] Accessing HttpOnly Cookies during Prerendering
To access cookies (including auth tokens) during prerendering, you can: 1. Inject IHttpContextAccessor in a service used only on the server side. 2. Access the cookie via: var token = httpContextAccessor.HttpContext?.Request.Cookies["YourCookieName"]; But be careful — this only works during prerendering on the server. 3. Make sure the service accessing the cookie is marked with [CascadingParameter] or injected differently between server/client, because once it switches to WASM, there’s no HttpContext.
27 replies
CC#
Created by TJ3046 on 4/17/2025 in #help
[SOLVED] Accessing HttpOnly Cookies during Prerendering
You're right — during the prerendering phase in Blazor WASM with server-side rendering, the component is rendered on the server, but the usual HttpContext isn't directly available in Blazor components.
27 replies