Click here to Skip to main content
14,836,551 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

Please suggest me to recognize the browser microsoft edge with any c# call.

I am tried with below.

System.Web.HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;

Thanks,
Ramana

What I have tried:

System.Web.HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
Posted
Updated 14-Jan-21 22:31pm
v3

This is how you do it, How to: Detect Browser Types and Browser Capabilities in ASP.NET Web Forms[^], although my version of Edge reports Request.Browser.Browser as Chrome so it does not work 100% as expected.

Just a note, it is bad practice to check for browser in c#. I'd suggest seeing if you can do what you need done a different way.
   
The Issue is that the HttpContext.Current.Request.Browser; detects Edge as Chrome browser.

So for the solution you can try Request.UserAgent to get the browser name, it will give string like this

"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Edg/87.0.664.75"

The Edg denotes the Edge browser with also version name after "/". In this way you can get every browser user agent string and identify the browser name if not works for Request.Browser object.

Also Code to Identify :

if (Request.UserAgent.IndexOf("Edg") > -1 )
{
// Edge Browser
}
   
v2
Comments
Richard Deeming 15-Jan-21 7:19am
   
That wouldn't detect the version of Edge which was around when this question was posted.

And browser sniffing is still a very bad idea. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900