Trouble getting User Agent from HttpContextAccessor

Hi,

I tried your sample code to make the sidebar of my Radzen app collapsed by default if the app is loaded on a mobile device. Therefore, I added the required code into the "MainLayout.razor" file which detects if I'm on a mobile system or not:

if (httpContextAccessor != null && httpContextAccessor.HttpContext != null &&
httpContextAccessor.HttpContext.Request != null && httpContextAccessor.HttpContext.Request.Headers.ContainsKey("User-Agent"))
{
...
}

Running this in Visual Studio works fine and can debug/step through the code. Now, I depolyed the app to an IIS server and the app is also running normal (everything is working), apart from the fact, that the code in if statement is never executed. It looks like the httpContextAccessor is null when being run on my server.

Any ideas what the problem could be? Maybe some kind of configuration issue?

Any help/ideas would be appreciated!

Update: I have discovered that the httpContextAccessor is not NULL but the httpContextAccessor.HttpContext is NULL at this point. According to the MS documentation, they do not recommend to use httpContextAccessor.HttpContext because it is not thread safe and can be NULL.

Since the code in the "protected override void OnInitialized()" is used in your sample project, what else could be done to get the user agent in order to expand/collapse the sidebar on mobile devices?