This issue is about how HttpContextAccessor isn't best practice for server side blazor apps. I am attempting to get the user-agent from the request in my server side app, but am running into the same issue discussed there. It's not an authentication problem, so using the Auth solution won't work for me. What is the right way to get the request info?
Asked
Active
Viewed 130 times
2
-
"It's not an authentication problem" but depending on your setup, this may be part of the solution. Are you using authentication? – Tewr Oct 30 '19 at 13:39
-
Yes, AzureAD. Is the user-agent in the authenticationprovider? – John D'Alessandro Oct 30 '19 at 13:42
-
1No I doubt that, but I think it's a good place to put it once you get your hands on it. The default AuthenticationStateProvider is interacting with the HttpContext to read headers and stuff when the connection is established, but after that the HttpContext is off limits. – Tewr Oct 30 '19 at 13:56
-
I dont have an answer for you, but I'd look into implementing a custom [AuthenticationStateProvider](https://learn.microsoft.com/en-us/aspnet/core/security/blazor/?view=aspnetcore-3.0&tabs=visual-studio#implement-a-custom-authenticationstateprovider). Normally you could add a dependency on HttpContextAccessor here – Tewr Oct 30 '19 at 14:02
-
1See my answer here: https://stackoverflow.com/questions/57982444/how-do-i-get-client-ip-and-browser-info-in-blazor/57983430#57983430 , which was not complete, and I had to ask the Blazor team about something missing in my answer, but they could really not help me much. https://github.com/aspnet/AspNetCore/issues/14167#issuecomment-533617987 – Oct 30 '19 at 15:56
-
@enet Wow that's disappointing. Seems like being able to get the request server side would have been in the 3.0 release since the plan was to have server side be production ready. – John D'Alessandro Oct 30 '19 at 18:05
-
Lots of things are still missing... – Oct 30 '19 at 18:19
-
1Can I ask why you want this? Perhaps there is a way to get to your ultimate goal. – Michael Washington Oct 30 '19 at 22:09
-
The site I'm working on is playing two roles depending on how it's accessed. From a browser is the default, but theres extra functionality when used in a plugin to another application through CEFSharp. So I was trying to use the user agent string to determine that, since the information I want is already there. My temporary fix is a url query parameter that has the info instead. – John D'Alessandro Nov 01 '19 at 10:51