79667655

Date: 2025-06-16 12:53:48
Score: 3
Natty:
Report link

As @Liero already mentioned the ˋHttpContextˋ should be avoided or used with caution.
So your main problems are with the authentication and the user preferences (I assume they are saved in the cookies).

The current user should be retrieved as @Liero also said using the ˋAuthenticationStateProviderˋ. I don't know whether the login works or not for you but a way I do it mostly is by forcing the Browser to send a POST request containing the form because the ˋHttpContextˋ is only in the initial request available.

To save the user preferences in a cookie you can use JsInterop to set and retrieve the cookie because this cookie don't need the http only option.

When you use Identity in Blazor you have pay attention that a valid ˋHttpContextˋ is available at the time when do stuff that e.g. sets a cookie or retrieves one. Do check this you can make the cascading ˋHttpContextˋ nullable at check if its null or not.

Are your questions answered now?

Reasons:
  • Whitelisted phrase (-1.5): you can use
  • Long answer (-0.5):
  • No code block (0.5):
  • Ends in question mark (2):
  • User mentioned (1): @Liero
  • User mentioned (0): @Liero
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: Suiram1