How do I access HttpContext in Server-side Blazor?

后端 未结 4 1889
感动是毒
感动是毒 2020-12-06 00:40

I need to access HttpContext in a page (.cshtml) and in particular a request and then a cookie. Despite available, HttpContextAccessor always has

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 01:06

    Please note that the documentation explicitly states that IHttpContextAccessor should not be used for Blazor apps: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-3.1#blazor-and-shared-state

    (This does not mean that in your particular case it will not work for a particular scenario. But as you are anyway only able to get the cookie from the first request - once SignalR takes over the are no cookies anymore - you should maybe get the value when _Host.cshtml is renderend, and pass it on as a string value to the Blazor components from there.)

提交回复
热议问题