Check out the latest documentation.

Redirect - All Versions

This element determines how mobile devices should be redirected. If it is omitted, redirection will be disabled. 51Degrees will continue to detect mobile devices and update the properties exposed through the Request.Browser collection.

Attributes

Mandatory

Description

mobileHomePageUrl

No (0.1.11.4 onwards)

A URL that will become the 'home page' for mobile devices (instead of the regular web site landing page). This is no longer mandatory as it can be completely replaced with the locations section, explained below. Otherwise it will redirect all mobile devices, including tablets.

firstRequestOnly

No

If set to 'true', only the first request received by the web site is redirected to the mobileHomePageUrl when the site is accessed from a mobile device. This allows developers to allow those using mobile devices to visit the standard site if they wish by placing a link to it within their mobile site. (Defaults to true)

Timeout

No

The number of minutes of inactivity that should occur before the requesting device is treated as making a new request to the web site for the purposes of redirection. If the session is available, the session timeout will be used and will override this value. (Defaults to 20 minutes)

devicesFile

No

A file used to store the details of devices that have previously accessed the web site to determine if they are making a subsequent request. The file will only be used if firstRequestOnly is set to true. The application pool identity must have read, write and modify access to the file. This setting is needed to ensure multiple worker processes have a consistent view of previous activity. (Random behaviour will be experienced if not specified on web sites with more than one worker process and firstRequestOnly set to true)

mobilePagesRegex

No

A regular expression that - when applied to the current request Path (context.Request. AppRelativeCurrentExecutionFilePath) - will return true if it should be considered a mobile page. Use this attribute to tell redirection about mobile pages derived from base classes such as System.Web.UI.Page. Redirection needs to be aware of mobile pages so that requests to these pages can be ignored and won't be redirected. To enable automatic redirection on pages other than those in the /Mobile directory, this setting will appear as mobilePagesRegex="~/Mobile/". Any page that derives from System.Web.UI.MobileControls.MobilePage will automatically be treated as a mobile page irrespective of this attribute.

originalUrlAsQueryString

No

(Version 0.1.11.1 onwards) If set to 'true', the redirected URL will have the original requesting URL encoded and included as the origUrl query string parameter in the redirected URL. This will enable the mobile home page to determine the original requested resource, providing the option to display a mobile-friendly version.

Note:  The URL defined by mobileHomePageUrl and the LoginUrl exposed through the property FormsAuthentication.LoginUrl will never be redirected. Redirecting these pages may prevent web sites operating as intended. Do not make the Login page the same as the main home page.

Locations Collection

locations is a collection of location elements that can be optionally provided under the redirect element. Location elements are evaluated in order to determine if they should be applied to the request and, if so, what URL should be used for the redirection. For example; a specific redirect location could be defined for tablet devices using the IsTablet  capability. The following example shows two location elements. The first redirects tablets while the second is standard mobile device redirection.



											
											<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>
											
										

The following tables contain the attributes available for the location element.

Attributes

Mandatory

Description

name

Yes

(Version 0.1.11.7 onwards) A unique identifier for that location. This name is also used for debugging in the log file.

url

Yes

The URL of the redirect location to use if all the properties in the collection match.

matchExpression

No

Can be used to provide a regular expression which will take the requesting URL as input match segments to be used in place of numeric parameters contained within {} in the URL attribute.

Each location element must have one or more filter ( add ) properties added to it. All the filter properties need to evaluate to true for the location to be used. The following table provides the attributes used by the add element.

Attributes Mandatory Description  

property

Yes

A property of HttpRequest HttpRequest.Browser or device data property to use when evaluating the matchExpression attributes. See  here for a full list of 51Degrees.com Lite and Premium properties.

matchExpression

Yes

A regular expression used to evaluate the value of the property.

If no location matches then the mobileHomePageUrl attribute of the redirect element (if provided) will be used if the requesting device is a mobile device.

origUrl Property

The location elements property attribute can also contain the value origUrl . This property will return the value of the original URL requested and can be used to turn redirection on or off based on the content of the URL. The following example could be used to redirect requests to the home page via the URL http://example.com only.
											
											<locations>
											
											
											<location
											
											
											name=
											
										"Home" 
											
											url=
											
										"~/Mobile/Default.aspx"
											
											>
											
											
											<add
											
											
											property=
											
										"IsTablet" 
											
											matchExpression=
											
										"true"
											
											/>
											
											
											<add
											
											
											property=
											
										"IsMobile" 
											
											matchExpression=
											
										"true"
											
											/>
											
											
											<add
											
											
											property=
											
										"origUrl" 
											
											matchExpression=
											
										"^http://example.com$"
											
											/>
											
											
											</location>
											
											
											</locations>
											
										


Dynamic Location URLs

The attribute matchExpression of the location element can be used to provide a regular expression that will extract one or more segments from the original URL. These segments can then be used to replace numeric parameter values within the url attribute value.

The following example will match everything from the original URL after the host name and replace the {0} with this value. Therefore the URL http://example.com/AboutUs.aspx would become http://example.com/Tablet/AboutUs.aspx if accessed from a tablet device.

											
											<redirect
											
											
											firstRequestOnly=
											
										"true"
 
											
											mobileHomePageUrl=
											
										"~/Mobile/Default.aspx"
 
											
											timeout=
											
										"20"
 
											
											devicesFile=
											
										"~/App_Data/Devices.dat"
 
											
											mobilePagesRegex=
											
										"/(Mobile|Tablet)/" 
											
											>
											
										
 
											
											<locations>
											
										
  
											
											<!--Send tablets to an equivalent version of the original page preserving
   the page name and query string.-->
											
										
  
											
											<location
											
											
											name=
											
										"tablet" 
											
											url=
											
										"~/Tablet/{0}" 
											
											matchExpression=
											
										"(?&lt;=^\w+://.+/).+"
											
											>
											
										
   
											
											<add
											
											
											property=
											
										"IsTablet" 
											
											matchExpression=
											
										"true"
											
											/>
											
										
  
											
											</location>
											
										
 
											
											</locations>
											
											
											</redirect>
											
										

Notice the 'less than' sign < in the regular expression needs to be encoded as &lt;