Writing headers directly vs deferred writing with middleware in blazor in static SSR Blazor?
22:00 12 May 2026

​IHttpContextAccessor is only reliably accessible inside static SSR components in Blazor. That being said, is it always safe to directly write headers through it inside OnInitialized(), or within Enhanced EditForm OnValidSubmit event handlers? I am using auth middleware by calling HttpContext.SignInAsync() through IHttpContextAccessor inside an Enhanced EditForm event handler, and it always works; but does that mean it would also be safe to set headers directly? And if not, why? Why does requesting to write headers in a deferred way through middleware work, while direct writing does not?

blazor blazor-server-side middleware