Friday, August 16, 2019

How do I get the name of the browser from the IHttpContextAccessor?

Following up on this, you can do something like this:

string browser = _accessor.HttpContext.Request.Headers["User-Agent"].ToString();

 
 

How well does this work? Well, I can get back some gunk that tells me if I am using Chrome which looks different than the gunk that comes back from Internet Explorer. However, the gunk that comes back for Internet Explorer doesn't say IE in it anywhere, so that is kinda lame. Sabina Spielrein might stress.

No comments:

Post a Comment