• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

Configuration

The following settings are needed at the top of the web.config file. Alternatively, they (and the rest of the Foundation configuration) can be placed in a file called '51Degrees.config' in the App_Data folder or in the root if the web application. This is to allow integration into Content Management Systems that separate the user away from the web.config.

These sections tells ASP.NET about subsequent configurations in the config and how to handle them. In this instance we are telling .NET to use the FiftyOne.Foundation assembly and classes to process the configuration elements.

<configSections>
  <sectionGroup name="fiftyOne">
    <section name="log"
              type="FiftyOne.Foundation.Mobile.Configuration.LogSection, FiftyOne.Foundation"
              requirePermission="false" 
              allowDefinition="Everywhere" 
              restartOnExternalChanges="false" 
              allowExeDefinition="MachineToApplication"/>
    <section name="redirect" 
              type="FiftyOne.Foundation.Mobile.Configuration.RedirectSection, FiftyOne.Foundation" 
              requirePermission="false" 
              allowDefinition="Everywhere" 
              restartOnExternalChanges="false" 
              allowExeDefinition="MachineToApplication"/>
    <section name="detection" 
              type="FiftyOne.Foundation.Mobile.Detection.Configuration.DetectionSection, FiftyOne.Foundation" 
              requirePermission="false" 
              allowDefinition="Everywhere" 
              restartOnExternalChanges="false" 
              allowExeDefinition="MachineToApplication"/>
    <section name="imageOptimisation" 
              type="FiftyOne.Foundation.Mobile.Configuration.ImageOptimisationSection, FiftyOne.Foundation" 
              requirePermission="false" 
              allowDefinition="Everywhere" 
              restartOnExternalChanges="false" 
              allowExeDefinition="MachineToApplication"/>
  </sectionGroup>
</configSections>

fiftyOne Section Element

You need to add the following element after the configSections element. These lines control how 51Degrees responds to mobile devices, where to locate the database of mobile devices, and whether to log events to a file. An example is shown below:

<fiftyOne>

 <redirect firstRequestOnly="true"
  timeout="20"
  devicesFile="~/App_Data/Devices.dat"
  mobilePagesRegex="/(Mobile|Tablet)/">
  <locations>
   <location name="tablet" url="~/Tablet/Default.aspx">
    <add property="IsTablet" matchExpression="true"/>
    <add property="IsMobile" matchExpression="true"/>
  </location>
  <location name="mobile" url="~/Mobile/Default.aspx">
    <add property="IsMobile" matchExpression="true"/>
   </location>
  </locations>
 </redirect>
  
 <log logFile="~/App_Data/Log.txt" logLevel="Info"/>
  
 <detection binaryFilePath="~/App_Data/51Degrees.dat" />

</fiftyOne>

Each element in the fiftyOne section plays an important role in the detector behaves. None of the elements are mandatory and may be omitted depending on your requirements. A working example config using the full range of settings and be found on our Codeplex repository.

.NET 2 and .NET 3.5 Applications

Older version of .NET need to be explicitly told which dlls to load. If these settings are not added the detector won't be able to enhance browser data or redirect to a mobile specific landing page. You do not need to follow these instructions for .NET applications.

Note: These elements have to be placed in the web.config file even if the previous configuration settings were placed in 51Degrees.config. You must also know what version of IIS you are running. The Visual Studio debug server requires the same setup as IIS 6.0

IIS 6.0 and Visual Studio

<!-- IIS 6.0 & Visual Studio - Registers a module that is used to detect any new requests
 to the web site. Without this module mobile detection and redirection won't work.
-->
<system.web>
 <httpModules>
  <add name="Detector" 
   type="FiftyOne.Foundation.Mobile.Detection.DetectorModule, FiftyOne.Foundation"/>
 </httpModules>
</system.web>

IIS 7.x & 8.x code

<system.webServer>
<!-- IIS 7.X - Registers a module that is used to detect any new requests to the
web site. Without this module mobile detection and redirection won't work.
-->
 <modules>
  <remove name="Detector"/>
   <add name="Detector" 
    type="FiftyOne.Foundation.Mobile.Detection.DetectorModule, FiftyOne.Foundation"/>
 </modules>
</system.webServer>

Need Help?