- Getting Started
- Upgrade V2 to V3
- Operational Summary
- Automatic Data Updates
- Web Applications
- trie matching
- Image Optimiser
- Passing Properties To Client Side
- Client Side Overrides
- User Performance Monitoring
- Offline Applications
- Accessing Metadata
- SQL Server
- IIS Modification
- Log Troubleshooting
- Native Code
- Examples And Questions
This getting started guide covers 3 common scenarios.
- A web site using .NET version 4 and NuGet package manager. This is the easiest installation and is recommended.
- A web site using .NET version 3.5 or one that does not have access to NuGet package manager.
- A project that is not a web site.
Choose the scenario which is most relevant to your project requirements.
In all scenarios three different device data sets can be used for device matching. By default the free Lite data set will be used and is shown in these getting started guides. Compare the differences between the different data sets and download free evaluations of paid for data to access enhanced features, more device properties and automatic updates.
1. .NET v4 Web Site & NuGet
Complete the following four steps to integrate mobile device detection into your Visual Studio 2012 .NET web application.
Step 1 - Search for 51Degrees in the Nuget package manager.
Step 2 - Press Install. Nuget will automatically add the necessary files and references to your project.
Step 3 - You can now use 51Degrees properties with the Request.Browser object using the following example code. An example web page will be available in the Mobile folder of the web site. If MVC is the target page type then the WebMatrix version of 51Degrees on NuGet will install an MVC Razor example web page. Access the web site from a mobile device to be redirected to the example web page.
Step 4 - If required reference the FiftyOne.Foundation.dll assembly from within Visual Studio to access the WebProvider as shown in the 2nd and 3rd lines of the OnInit example method below.
2. .NET 3.5 Web Site or No NuGet
All the files needed to add 51Degrees to an existing project (including one that is not a web site) are also available from Codeplex by downloading the zip file titled 51Degrees DLL Website Enhancer . The following files are included:
|.NET v4 assembly for 51Degrees.
|.NET v3.5 assembly for 51Degrees
|Configuration file for 51Degrees
|An example web forms page to test functionality
Place the 51Degrees.config file in either the App_Data folder or the root folder for the web site.
The 51Degrees.config file contains logic to redirect a mobile device to the M.aspx also provided in the zip file. Place the M.aspx file in the root folder of the web site.
Depending on the version of .NET being used follow one of the next two steps.
.NET 4 or Later
Copy the DLL from NET4 directory in to your project's bin directory.
Web sites running .NET v4 enable assemblies to register themselves automatically when the web site starts. Therefore they do not need to be referenced in the web.config file. If the detection functionality fails to work it's possible the website has been configured to prevent the automatic registration of assemblies. If this happens continue to the instructions for .NET 3.5 which explain how to explicitly register the assembly with the website.
The following entries need to be added to your existing web.config file for mobile device detection and redirection to be enabled. The comments in green do not need to be inserted but have been included for easy reference.
Where a section already exists with the primary element name, configSections or system.web/httpModules insert the section highlighted in grey before the closing tag.
For IIS 6.0 or IIS7 in Classic Mode
For IIS 7.0 and above in Integrated Mode
Access the web site from a mobile device, or emulator, and confirm that the M.aspx page is being deployed.
If you require more than the simple redirection service and properties exposed via the Request.Browser class reference the assembly from within the Visual Studio project. The sample code shown for NuGet at the top of this page can be used to interface with 51Degrees.
For more information on the configuration options available for web applications see the Web Applications documentation.
3. Non Web Site Projects
Start by referencing the FiftyOne.Foundation.dll assembly contained in the 51Degrees DLL Website Enhancer explained in the above section from within the Visual Studio project choosing the relevant .NET version.
Important : Ensure the Target Framework of your project is NOT set to the Client Profile version of .NET.
Download from Codeplex the file 51Degrees Lite Device Data and decompress it.
The following example code shows how to create a data set and provider for the purposes of device detection using an example User-Agent string.
For more information on using 51Degrees in non web project see the Offline Applications documentation.
3.1 Example of an Offline Command-Line C# Application
The following example implements the most basic analysis of User-Agents log file. For the purpose of this program both the 51Degrees-Lite.dat file and the text file containing User-Agent strings are located in C:/data/ directory. The User-Agents text file contains one User-Agent per line.
Please note, you can also use the million.csv file that is available for download from the 51Degrees website as the User-Agent data/log file (not the 51Degrees-Lite.dat).
- Start by creating a new C# - Windows - Console Application project.
- Now, copy the correct DLL to your bin directory. This will either be NET 4 or NET 3.5 DLL. If you are not sure please read section 2 of "Getting Started" section of .NET.
- If a reference to 51Degrees DLL does not appear add it manually by right-clicking on "References" in Solution Explorer and choosing "Add Reference" as shown below:
- In the reference manager window that opened select the "Browse" button at the bottom of the window. A file explorer will open. Navigate to the bin folder containing the 51Degrees DLL and select the 51Degrees DLL. Click "Add".
- Now you are ready to use the 51Degrees DLL. The snippet below demonstrates how a text file with User-Agent strings can be opened, read in line by line with each line containing a User-Agent. Each line would be matched and the results displayed.
The above code should produce output similar to the one shown below: