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 CPOL
Using and updating your machine.config file to better detect browser type in ASP.NET
using System;
using NUnit.Framework;

namespace Ocean.Nunit.HttpCapabilities.CodeProject
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	[TestFixture]
	public class CapabiltiesMobile
	{
		Ocean.Web.HttpCapabilities.Settings Browser;
		public CapabiltiesMobile()
		{
			Browser = new Ocean.Web.HttpCapabilities.Settings(Ocean.Web.HttpCapabilities.EmbededFile.CodeProject);
		}

		[Test]
		public void Test_Gateway()
		{
			Ocean.Web.HttpCapabilities.Result R;
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("MOT-1.2.0/11.03 UP.Browser/4.1.27a UP.Link/4.3.2 (Google WAP Proxy/1.0)");
			Assert.AreEqual("UP.Link/4.3.2",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("4",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".3",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".2",R["gatewayRevisionVersion"], "gatewayRevisionVersion");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("MOT-A-0A/00.04 UP.Browser/4.1.27a1 UP.Link/4.2.3.5c");
			Assert.AreEqual("UP.Link/4.2.3.5c",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("4",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".2",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".3",R["gatewayRevisionVersion"], "gatewayRevisionVersion");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("MOT-A-0A/00.06 UP.Browser/4.1.27a1 UP.Link/4.2.3.5c");
			Assert.AreEqual("UP.Link/4.2.3.5c",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("4",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".2",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".3",R["gatewayRevisionVersion"], "gatewayRevisionVersion");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("MOT-A-0A/00.06 UP.Browser/4.1.27a1 UP.Link/4.2.3.5h");
			Assert.AreEqual("UP.Link/4.2.3.5h",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("4",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".2",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".3",R["gatewayRevisionVersion"], "gatewayRevisionVersion");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("MOT-MCCB/7582 UP.Browser/4.1.23 UP.Link/4.2.1.1");
			Assert.AreEqual("UP.Link/4.2.1.1",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("4",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".2",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".1",R["gatewayRevisionVersion"], "gatewayRevisionVersion");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("MOT-SAP4_/11.03 UP.Browser/4.1.23c UP.Link/5.1.1.2a");
			Assert.AreEqual("UP.Link/5.1.1.2a",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("5",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".1",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".1",R["gatewayRevisionVersion"], "gatewayRevisionVersion");
		
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------			
			R = Browser.Process("MOT-61/04.02 UP/4.1.17r UP.Browser/4.1.17r-XXXX UP.Link/4.2.3.5h (Google WAP Proxy/1.0)");   
			Assert.AreEqual("UP.Link/4.2.3.5h",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("4",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".2",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".3",R["gatewayRevisionVersion"], "gatewayRevisionVersion");
					
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("MOT-V220/0B.D1.1BR MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.0 UP.Link/1.1 (Google WAP Proxy/1.0)");  
			Assert.AreEqual("UP.Link/1.1",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("1",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".1",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual("0",R["gatewayRevisionVersion"], "gatewayRevisionVersion");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("SonyEricssonT630/R401 Profile/MIDP-1.0 Configuration/CLDC-1.0 UP.Link/5.1.1.4");
			Assert.AreEqual("UP.Link/5.1.1.4",R["gatewayVersion"], "Browser Name Compare");
			Assert.AreEqual("5",R["gatewayMajorVersion"], "gatewayMajorVersion");
			Assert.AreEqual(".1",R["gatewayMinorVersion"], "gatewayMinorVersion");
			Assert.AreEqual(".1",R["gatewayRevisionVersion"], "gatewayRevisionVersion");

		}

		[Test]
		public void Test_DoCoMo()
		{
			Ocean.Web.HttpCapabilities.Result R;
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("DoCoMo/1.0/D503iS/c10");
			Assert.AreEqual("i-mode",R.Browser, "Browser Name Compare");   
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");   
			Assert.AreEqual("Mitsubishi",R.MobileDeviceManufacturer, "MobileDeviceManufacturer"); 
			Assert.AreEqual("D503iS",R.MobileDeviceModel, "Browser Version Compare");  
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("DoCoMo/1.0/N504i/c10/TB");
			Assert.AreEqual("i-mode",R.Browser, "Browser Name Compare");
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare"); 
			Assert.AreEqual("NEC",R.MobileDeviceManufacturer, "Browser Version Compare");
			Assert.AreEqual("N504i",R.MobileDeviceModel, "Browser Version Compare");  
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("DoCoMo/1.0/P504iS/c10/TB");
			Assert.AreEqual("i-mode",R.Browser, "Browser Name Compare");
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");
			Assert.AreEqual("Panasonic",R.MobileDeviceManufacturer, "Browser Version Compare");
			Assert.AreEqual("P504iS",R.MobileDeviceModel, "Browser Version Compare"); 
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("DoCoMo/2.0 P900i(c100;TB;W24H11)");
			Assert.AreEqual("i-mode",R.Browser, "Browser Name Compare");
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");
			Assert.AreEqual("Panasonic",R.MobileDeviceManufacturer, "Browser Version Compare");
			Assert.AreEqual("P900i",R.MobileDeviceModel, "Browser Version Compare"); 
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");	
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("DoCoMo/1.0/P502i/c10 (Google CHTML Proxy/1.0)");   
			Assert.AreEqual("i-mode",R.Browser, "Browser Name Compare");   
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");   
			Assert.AreEqual("Panasonic",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");   
			Assert.AreEqual("P502i",R.MobileDeviceModel, "Browser Version Compare"); 
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("DoCoMo/2.0 SH900i(c100;TB;W24H12)");   
			Assert.AreEqual("i-mode",R.Browser, "Browser Name Compare");   
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");   
			Assert.AreEqual("Sharp",R.MobileDeviceManufacturer, "MobileDeviceManufacturer"); 
			Assert.AreEqual("SH900i",R.MobileDeviceModel, "Browser Version Compare");   
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
		}

		[Test]
		public void	Test_Misc()
		{
			Ocean.Web.HttpCapabilities.Result R;	
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("UP.Browser/3.04-SN17 UP.Link/3.4.5.6");
			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");
			Assert.AreEqual("3.04",R.Version, "Browser Version Compare");
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("UP.Browser/3.1.04-DS15 UP.Link/5.0.2.9 (Google WAP Proxy/1.0)");
			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");
			Assert.AreEqual("3.1",R.Version, "Browser Version Compare");
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("UP.Browser/6.1.0.1.140 (Google CHTML Proxy/1.0)");
			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("AUDIOVOX-CDM9155SP/07.60 UP.Browser/4.1.26c3 UP.Link/5.0.2.8 (Google WAP Proxy/1.0)"); 
//            Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("4.1",R.Version, "Browser Version Compare"); 
//			Assert.AreEqual("Audiovox",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("CDM9155SP",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("jBrowser (Google WAP Proxy/1.0)");  
			Assert.AreEqual("Jataayu jBrowser",R.Browser, "Browser Name Compare");  
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");   
			Assert.AreEqual("Jataayu",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
			Assert.AreEqual("jBrowser",R.MobileDeviceModel, "Browser Version Compare");  
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
			
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
			R = Browser.Process("jBrowser/J2ME Profile/MIDP-1.0 Configuration/CLDC-1.0 (Google WAP Proxy/1.0)");  
			Assert.AreEqual("Jataayu jBrowser",R.Browser, "Browser Name Compare");  
			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");   
			Assert.AreEqual("Jataayu",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
			Assert.AreEqual("jBrowser",R.MobileDeviceModel, "Browser Version Compare");  
			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
					
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
//			R = Browser.Process("OPWV-SDK/62 UP.Browser/6.2.2.1.208 (GUI) MMP/2.0"); 
//			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("6.2",R.Version, "Browser Version Compare");   
//			Assert.AreEqual("Openwave",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("Openwave 6.2 emulator",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
								
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
//			R = Browser.Process("SAGEM-myX-5/2.0 UP.Browser/5.0.3.3.1.c.1 (GUI) (Google WAP Proxy/1.0)"); 
//			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("5.0",R.Version, "Browser Version Compare");   
//			Assert.AreEqual("Sagem",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("myX5-2",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
		}

		[Test]
		public void	Test_Sprint()
		{
					
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
//			R = Browser.Process("LGE-LG4600 UP.Browser/6.2.2.3.d.1.104 (GUI) MMP/2.0 (Google WAP Proxy/1.0)"); 
//			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("0.0",R.Version, "Browser Version Compare");   
//			Assert.AreEqual("Sprint",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("LG4600",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");

			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
//			R = Browser.Process("LGE-AX5450 UP.Browser/4.1.27 UP.Link/4.2.1.1"); 
//			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("4.1",R.Version, "Browser Version Compare");   
//			Assert.AreEqual("Sprint",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("AX5450",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
								
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
//			R = Browser.Process("LGE-LX5350/1.0 UP.Browser/6.1.0.2.135 (GUI) MMP/2.0"); 
//			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("6.1",R.Version, "Browser Version Compare");   
//			Assert.AreEqual("Sprint",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("LX5350",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");
								
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
//			R = Browser.Process("LGE-LX5350/4.0 UP.Browser/6.2.0.1.185 (GUI) MMP/2.0"); 
//			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("6.2",R.Version, "Browser Version Compare");   
//			Assert.AreEqual("Sprint",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("LX5350",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice Compare");

											
			//-------------------------------------------------------------------
			//
			//-------------------------------------------------------------------
//			R = Browser.Process("LGE-TM520/1.0 UP.Browser/4.1.22b UP.Link/4.3.4.4d"); 
//			Assert.AreEqual("Phone.com",R.Browser, "Browser Name Compare");   
//			Assert.AreEqual("4.1",R.Version, "Browser Version Compare");   
//			Assert.AreEqual("Sprint",R.MobileDeviceManufacturer, "MobileDeviceManufacturer");  
//			Assert.AreEqual("TM520",R.MobileDeviceModel, "Browser Version Compare");  
//			Assert.AreEqual(true,R.isMobileDevice, "isMobileDevice 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 | Terms of Use | Mobile
Web01 | 2.8.150326.1 | Last Updated 6 May 2009
Article Copyright 2004 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid