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
<project name="Ocean.HttpCapabilities" default="Release">
	<property name="build.basedir" value=".\bin" />
	<property name="build.dir" value=".\bin" />
	<property name="debug" value="false" />
	<property name="unsafe" value="false" />
	<property name="checked" value="false" />
	<property name="define" value="" />
	<property name="warninglevel" value="1" />
	<property name="FrameworkPath" value="C:\WINDOWS\Microsoft.NET\Framework" />
	<target name="Release" depends="Release.CopyRefs,Ocean.Web.HttpCapabilities,Ocean.cmd.HttpCapabilities,Ocean.Nunit.HttpCapabilities" />
	<target name="setup">
		<mkdir dir="${build.dir}" />
	</target>
	<target name="Release.CopyRefs">
		<property name="build.dir" value="${build.basedir}\Release" />
	</target>
	<target name="Ocean.cmd.HttpCapabilities" depends="setup,Ocean.Web.HttpCapabilities">
		<property name="project.name" value="Ocean.Cmd.HttpCapabilities" />
		<property name="build.dir" value="${build.basedir}\Release" />
		<property name="output" value="${build.dir}\Ocean.Cmd.HttpCapabilities.exe" />
		<csc unsafe="${unsafe}" checked="${checked}" target="exe" output="${output}" debug="${debug}"
			define="${define}" warninglevel="${warninglevel}">
			<sources>
				<include name="cmd\HttpCapabilities\AssemblyInfo.cs" />
				<include name="cmd\HttpCapabilities\HttpCapabilities.cs" />
			</sources>
			<references>
				<include name="${FrameworkPath}\System.dll" />
				<include name="${FrameworkPath}\System.Data.dll" />
				<include name="${FrameworkPath}\System.XML.dll" />
				<include name="${FrameworkPath}\System.Web.dll" />
				<include name="${build.dir}\Ocean.Web.HttpCapabilities.dll" />
			</references>
		</csc>
	</target>
	<target name="Ocean.Web.HttpCapabilities" depends="setup">
		<property name="project.name" value="Ocean.Web.HttpCapabilities" />
		<property name="build.dir" value="${build.basedir}\Release" />
		<property name="output" value="${build.dir}\Ocean.Web.HttpCapabilities.dll" />
		<csc unsafe="${unsafe}" checked="${checked}" target="library" output="${output}" debug="${debug}"
			define="${define}" warninglevel="${warninglevel}">
			<sources>
				<include name="Web\HttpCapabilities\AssemblyInfo.cs" />
				<include name="Web\HttpCapabilities\CaseFilter.cs" />
				<include name="Web\HttpCapabilities\Enums.cs" />
				<include name="Web\HttpCapabilities\Result.cs" />
				<include name="Web\HttpCapabilities\SectionHandler.cs" />
				<include name="Web\HttpCapabilities\Settings.cs" />
			</sources>
			<references>
				<include name="${FrameworkPath}\System.XML.dll" />
				<include name="${FrameworkPath}\System.dll" />
				<include name="${FrameworkPath}\System.Web.dll" />
				<include name="${FrameworkPath}\System.Data.dll" />
			</references>
			<arg value="/resource:Web\HttpCapabilities\Resources\xml.BrowserCap,Ocean.Web.HttpCapabilities.Resources.xml.BrowserCap" />
			<arg value="/resource:Web\HttpCapabilities\Resources\xml.Mobile,Ocean.Web.HttpCapabilities.Resources.xml.Mobile" />
			<arg value="/resource:Web\HttpCapabilities\Resources\xml.SpidersBots,Ocean.Web.HttpCapabilities.Resources.xml.SpidersBots" />
			<arg value="/resource:Web\HttpCapabilities\Resources\xml.CodeProject,Ocean.Web.HttpCapabilities.Resources.xml.CodeProject" />
		</csc>
	</target>
	<target name="Ocean.Nunit.HttpCapabilities" depends="setup">
		<property name="project.name" value="Ocean.Nunit.HttpCapabilities" />
		<property name="build.dir" value="${build.basedir}\Release" />
		<property name="output" value="${build.dir}\Ocean.Nunit.HttpCapabilities.dll" />
		<csc unsafe="${unsafe}" checked="${checked}" target="library" output="${output}" debug="${debug}"
			define="${define}" warninglevel="${warninglevel}">
			<sources>
				<include name="Nunit\HttpCapabilities\AssemblyInfo.cs" />
				<include name="Nunit\HttpCapabilities\Capabilities_Amiga.cs" />
				<include name="Nunit\HttpCapabilities\Capabilities_Macintosh.cs" />
				<include name="Nunit\HttpCapabilities\Capabilities_Microsoft.cs" />
				<include name="Nunit\HttpCapabilities\Capabilities_OSPlatform.cs" />
				<include name="Nunit\HttpCapabilities\CapabilitiesSpiders.cs" />
				<include name="Nunit\HttpCapabilities\CapabilitiesTest.cs" />
				<include name="Nunit\HttpCapabilities\CapabiltiesMobile.cs" />
				<include name="Nunit\HttpCapabilities\CapabiltiesMobile_Ericsson.cs" />
				<include name="Nunit\HttpCapabilities\CapabiltiesMobile_Motorola.cs" />
				<include name="Nunit\HttpCapabilities\CapabiltiesMobile_Nokia.cs" />
				<include name="Nunit\HttpCapabilities\CapabiltiesMobile_Samsung.cs" />
				<include name="Nunit\HttpCapabilities\CapabiltiesMobile_Sharp.cs" />
				<include name="Nunit\HttpCapabilities\CapabiltiesMobile_Siemens.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\Capabilities_Gecko.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\Capabilities_Konqueror.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\Capabilities_Macintosh.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\Capabilities_Microsoft.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\Capabilities_Netscape.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\Capabilities_Opera.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\CapabiltiesMobile.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\CapabiltiesMobile_Ericsson.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\CapabiltiesMobile_Motorola.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\CapabiltiesMobile_Nokia.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\CapabiltiesMobile_Samsung.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\CapabiltiesMobile_Sharp.cs" />
				<include name="Nunit\HttpCapabilities\CodeProject\CapabiltiesMobile_Siemens.cs" />
			</sources>
			<references>
				<include name="${FrameworkPath}\System.dll" />
				<include name="${FrameworkPath}\System.Data.dll" />
				<include name="${FrameworkPath}\System.XML.dll" />
				<include name="${FrameworkPath}\System.Web.dll" />
				<include name="C:\Program Files\NUnit 2.2\bin\nunit.framework.dll" />
				<include name="${build.dir}\Ocean.Web.HttpCapabilities.dll" />
			</references>
		</csc>
	</target>
	<target name="Clean">
		<delete file="${build.dir}\Ocean.Web.HttpCapabilities.dll" failonerror="false" />
		<delete file="${build.dir}\Ocean.Web.HttpCapabilities.pdb" failonerror="false" />
		<delete file="${build.dir}\Ocean.Nunit.HttpCapabilities.dll" failonerror="false" />
		<delete file="${build.dir}\Ocean.Nunit.HttpCapabilities.pdb" failonerror="false" />
		<delete file="${build.dir}\Ocean.Cmd.HttpCapabilities.exe" failonerror="false" />
		<delete file="${build.dir}\Ocean.Cmd.HttpCapabilities.pdb" failonerror="false" />
	</target>
	<target name="nunit.Release" depends="Release">
		<nunit2>
			<formatter type="Xml" usefile="true" extension=".xml" outputdir="${build.dir}" />
			<test assemblyname="${build.dir}\Ocean.Nunit.HttpCapabilities.dll" />
		</nunit2>
	</target>
</project>

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)

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
Web02 | 2.8.140721.1 | Last Updated 6 May 2009
Article Copyright 2004 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid