Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

Browser Detection using ASP.NET

, 6 May 2009
Using and updating your machine.config file to better detect browser type in ASP.NET
using System;
using NUnit.Framework;

namespace Ocean.Nunit.HttpCapabilities
{
	/// <summary>
	/// Summary description for Capabilities_OS.
	/// </summary>
	[TestFixture]
	public class Capabilities_OSPlatform
	{
		Ocean.Web.HttpCapabilities.Settings Browser;
		Ocean.Web.HttpCapabilities.Result R;
		public Capabilities_OSPlatform()
		{
			Browser = new Ocean.Web.HttpCapabilities.Settings(Ocean.Web.HttpCapabilities.EmbededFile.BrowserCap);
		}

		[Test]
		public void	Test_Amiga()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.0 (compatible; AmigaOS; Chimera)");                        
			Assert.AreEqual("Amiga",R.Platform, "Browser Platform Compare");                 
			Assert.AreEqual("AmigaOS",R.OS, "Browser OS Compare");                 

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("IBrowse/2.3 (AmigaOS 3.9)");              
			Assert.AreEqual("Amiga",R.Platform, "Browser Platform Compare");                 
			Assert.AreEqual("AmigaOS 3.9",R.OS, "Browser OS Compare"); 

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.0 (compatible; IBrowse 3.0; AmigaOS4.0)");                    
			Assert.AreEqual("Amiga",R.Platform, "Browser Platform Compare");                 
			Assert.AreEqual("AmigaOS 4.0",R.OS, "Browser OS Compare"); 
 
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("AmigaVoyager/2.95 (compatible; MC680x0; AmigaOS)");
			Assert.AreEqual("Amiga",R.Platform, "Browser Version Compare");
			Assert.AreEqual("AmigaOS",R.OS, "Browser Version Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("AmigaVoyager/3.2 (AmigaOS/MC680x0)");
			Assert.AreEqual("Amiga",R.Platform, "Browser Version Compare");
			Assert.AreEqual("AmigaOS",R.OS, "Browser Version Compare");

		}
		
		[Test]
		public void	Test_Microsoft_NT4()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101");              
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows NT 4.0",R.OS, "Browser OS Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; .NET CLR 1.0.3705)");
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows NT 4.0",R.OS, "Browser OS Compare");  

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------            
			R = Browser.Process("Mozilla/4.06 [en] (WinNT; U)");                     
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows NT",R.OS, "Browser OS Compare");    


		}
		[Test]
		public void	Test_Microsoft_2000()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Konqueror2)");       
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 2000",R.OS, "Browser OS Compare");  

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------                  
			R =Browser.Process("Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 5.11  [en]");    
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 2000",R.OS, "Browser OS Compare"); 

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/5.0 (Windows 2000; U) Opera 6.04  [en]");        
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 2000",R.OS, "Browser OS Compare"); 

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; (R1 1.3); .NET CLR 1.1.4322)");      
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 2000",R.OS, "Browser OS Compare");  
   
		}
		[Test]
		public void	Test_Microsoft_XP()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/3.0 (Windows NT 5.1; U) Opera 7.23  [en]"); 
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows XP",R.OS, "Browser OS Compare");    

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.0  [en]");       
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows XP",R.OS, "Browser OS Compare");
		}
		[Test]
		public void	Test_Microsoft_2003()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2) Opera 7.51  [en]");  
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows Server 2003",R.OS, "Browser OS Compare");                      

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------			
			R =Browser.Process("Opera/7.23 (Windows NT 5.2; U)  [en]");             
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows Server 2003",R.OS, "Browser OS Compare");   

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.41115)");
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("Microsoft Windows Server 2003",R.OS, "Browser OS Compare");

			//-------------------------------------------------------------------
			//This one I am unsure of if it is windows 2003 or a private alpha build
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 6.0; .NET CLR 2.0.31113)");
			Assert.AreEqual("WinNT",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("Microsoft Windows Server 2003",R.OS, "Browser OS Compare");
		}
		[Test]
		public void Test_Microsoft_311()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/2.0 (compatible; MSIE 3.02; Windows 3.1)"); 
			Assert.AreEqual("Win16",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 3.1",R.OS, "Browser OS Compare");   
		}
		[Test]
		public void Test_Microsoft_95()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/4.06 (Win95; I)");                          
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 95",R.OS, "Browser OS Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/4.0 (compatible; MSIE 5.0; Windows 95) Opera 6.01  [en]");      
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 95",R.OS, "Browser OS Compare");      

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/2.0 (compatible; MSIE 3.01; AK; Windows 95)");                  
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 95",R.OS, "Browser OS Compare");    
		}
		[Test]
		public void Test_Microsoft_98()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/3.0 (Windows 98; U) Opera 6.05  [en]");     
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 98",R.OS, "Browser OS Compare");    
  
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------  
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 98)");             
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 98",R.OS, "Browser OS Compare");    

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------  
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 5.0; Win98 A; ATHMWWW1.1; MSOCD;)");      
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 98",R.OS, "Browser OS Compare");    

			R = Browser.Process("Mozilla/4.06 [en] (Win98; I)");                     
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows 98",R.OS, "Browser OS Compare");    
		}
		[Test]
		public void Test_Microsoft_ME()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/4.0 (compatible; MSIE 5.0; Windows ME) Opera 5.11 [en]");       
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows ME",R.OS, "Browser OS Compare");    
            
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------            
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 5.5; AOL 5.0; Windows 98; Win 9x 4.90)"); 
			Assert.AreEqual("Win9X",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft Windows ME",R.OS, "Browser OS Compare");    
  
		}
		[Test]
		public void Test_Microsoft_WebTV()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("Mozilla/3.0 WebTV/1.2 (compatible; MSIE 2.0)");     
			Assert.AreEqual("WebTV",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Microsoft WebTV",R.OS, "Browser OS Compare");
		}
		[Test]
		public void Test_Macintosh_OSX()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		

			R = Browser.Process("iCab/2.9.5 (Macintosh; U; PPC; Mac OS X)");     
			Assert.AreEqual("MacPPC",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Macintosh OS X",R.OS, "Browser OS Compare");         
		}
		[Test]
		public void Test_Macintosh_68K()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("Mozilla/3.01Gold (Macintosh; I; 68K)");             
			Assert.AreEqual("Mac68K",R.Platform, "Browser Platform Compare"); 
			Assert.AreEqual("Macintosh 68K",R.OS, "Browser OS Compare");    

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("iCab/2.8.2 (Macintosh; U; 68K)");     
			Assert.AreEqual("Mac68K",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Macintosh 68K",R.OS, "Browser OS Compare");         
		}
		[Test]
		public void Test_Macintosh_Darwin()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("Links (0.98; Darwin 7.3.0 Power Macintosh)");       
			Assert.AreEqual("MacPPC",R.Platform, "Browser Platform Compare"); 
			Assert.AreEqual("Macintosh Darwin",R.OS, "Browser OS Compare");
			Assert.AreEqual(false,R.IsBot, "Browser Bot Compare");       
		}
		[Test]
		public void Test_Macintosh_PPC()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R =Browser.Process("Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC) Opera 5.0  [en]");       
			Assert.AreEqual("MacPPC",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("Macintosh PPC",R.OS, "Browser OS Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------	
			R = Browser.Process("Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Mac_PPC)");                
			Assert.AreEqual("MacPPC",R.Platform, "Browser Platform Compare"); 
			Assert.AreEqual("Macintosh PPC",R.OS, "Browser OS Compare"); 

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------	
			R = Browser.Process("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; da-dk) AppleWebKit/85 (KHTML, like Gecko) Safari/85");
			Assert.AreEqual("MacPPC",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("Macintosh OS X",R.OS, "Browser OS Compare");         
		}
		[Test]
		public void Test_linux()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("Mozilla/5.0 (compatible; Konqueror/2.2-11; Linux)");
			Assert.AreEqual("Unknown",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("Linux",R.OS, "Browser OS Compare"); 

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("Mozilla/5.0 (compatible; Konqueror/3.0-rc1; i686 Linux; 20020104)");    
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");             
			Assert.AreEqual("Linux",R.OS, "Browser OS Compare");  

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("Links (2.1pre9; Linux 2.4.20-gentoo-r5 i686; 141x46)");                 
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");             
			Assert.AreEqual("Linux",R.OS, "Browser OS Compare");  

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------		
			R = Browser.Process("ELinks/0.9.CVS (textmode; Linux 2.6.8.1-ck5 i686; 200x93-3)");       
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");             
			Assert.AreEqual("Linux",R.OS, "Browser OS Compare"); 
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040806");     
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");             
			Assert.AreEqual("Linux",R.OS, "Browser OS Compare");  
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Opera/7.23 (X11; FreeBSD i386; U)  [en]");          
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");           
			Assert.AreEqual("FreeBSD",R.OS, "Browser OS Compare");
		}
		[Test]
		public void Test_freebsd()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------						
			R = Browser.Process("Links (2.0; FreeBSD 5.0-RELEASE i386; 80x25)");     
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");           
			Assert.AreEqual("FreeBSD",R.OS, "Browser OS Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Links (2.1pre14; FreeBSD 4.10-RELEASE i386; x)");     
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");           
			Assert.AreEqual("FreeBSD",R.OS, "Browser OS Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/5.0 (compatible; Konqueror/2.2.2; FreeBSD)");                   
			Assert.AreEqual("Unknown",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("FreeBSD",R.OS, "Browser OS Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Opera/7.23 (X11; FreeBSD i386; U)  [en]");          
			Assert.AreEqual("Intel",R.Platform, "Browser Platform Compare");           
			Assert.AreEqual("FreeBSD",R.OS, "Browser OS Compare");
		}

		[Test]
		public void Test_OpenBSD()
		{
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Mozilla/5.0 (compatible; Konqueror/3.1; OpenBSD)"); 
			Assert.AreEqual("Unknown",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("OpenBSD",R.OS, "Browser OS Compare");
		}
		[Test]
		public void Test_NetBSD()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("Links (2.1pre15; NetBSD 1.6.1 alpha; 110x35)");       
			Assert.AreEqual("Alpha",R.Platform, "Browser Platform Compare"); 
			Assert.AreEqual("NetBSD",R.OS, "Browser OS Compare"); 
		}
		[Test]
		public void Test_SunOS()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:0.9.4.1) Gecko/20020518 Netscape6/6.2.3");   
			Assert.AreEqual("SunOS",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("SunOS",R.OS, "Browser OS Compare");  

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.0.0) Gecko/20020605");    
			Assert.AreEqual("SunOS",R.Platform, "Browser Platform Compare");  
			Assert.AreEqual("SunOS",R.OS, "Browser OS Compare");  
		}
		[Test]
		public void Test_IRIX()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/4.75 [en] (X11; I; IRIX64 6.5 IP30)");
			Assert.AreEqual("SGI IRIX",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("SGI IRIX",R.OS, "Browser OS Compare"); 
		}
		[Test]
		public void Test_OSF1()
		{
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R =Browser.Process("Mozilla/4.76 [en] (X11; U; OSF1 V5.1 alpha)");
			Assert.AreEqual("Alpha",R.Platform, "Browser Platform Compare");
			Assert.AreEqual("OSF1",R.OS, "Browser OS Compare"); 
		}
		[Test]
		public void Test_OpenVMS()
		{
			R =Browser.Process("Mozilla/5.0 (X11; U; OpenVMS AlphaServer_300_4/266; en-US; rv:1.5) Gecko/20040116");     
			Assert.AreEqual("Alpha",R.Platform, "Browser Platform Compare");             
			Assert.AreEqual("OpenVMS",R.OS, "Browser OS Compare");  
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.
 
His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.
 
He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.
 
Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 6 May 2009
Article Copyright 2004 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid