string strUserAgent = Request.UserAgent.ToString().ToLower();
if (strUserAgent != null)
{
if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains("iphone") ||
strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") ||
strUserAgent.Contains("palm"))
{
Response.Redirect("DefaultMobile.aspx");
}
}
<configSections>
<sectionGroup name="mobile">
<section name="toolkit" type="Mobile.Configuration.ToolkitSection, Mobile, Version=0.1.5.0, Culture=neutral" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>
<section name="wurfl" type="Mobile.Devices.Wurfl.Configuration.WurflSection, Mobile, Version=0.1.5.0, Culture=neutral" allowDefinition="Everywhere" restartOnExternalChanges="false" allowExeDefinition="MachineToApplication"/>
</sectionGroup>
</configSections>
<mobile>
<!-- When a mobile device is found to be accessing a non mobile page the mobileRedirectUrl setting is used to redirect the browser to a landing page for mobile devices.-->
<toolkit mobileRedirectUrl="~/M.aspx" logFile="~/App_Data/Log.txt" logLevel="Debug"/>
<!-- The following settings provided the location of wurfl files. wurflFilePath is the path of the main wurfl file (mandatory). newDevicesPatchFile shows where devices that aren't matched exactly should be stored (optional). wurflPatches defines where any additional patch files can be located (optional).-->
<wurfl wurflFilePath="~/App_Data/wurfl.xml.gz">
<wurflPatches>
<add name="browser_definitions" filePath="~/App_Data/web_browsers_patch.xml.gz" enabled="true"/>
</wurflPatches>
</wurfl>
</mobile>
<httpModules>
<add name="Detector" type="Mobile.Browser.Detector, Mobile, Version=0.1.5.0"/>
</httpModules>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="M.aspx.cs" Inherits="M" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<html xmlns="http://www.w3.org/1999/xhtml"
<body>
<mobile:Form id="Form1" runat="server">
<mobile:Label ID="LabelMobile" Runat="server" Alignment="Center" Font-Size="Large" Text="This is a Mobile Device Redirection." />
<mobile:Label ID="LabelManufacturer" Runat="server" Alignment="Center" Font-Size="Normal"/>
<mobile:Label ID="LabelModel" Runat="server" Alignment="Center" Font-Size="Normal"/>
<mobile:Label ID="LabelScreen" Runat="server" Alignment="Center" Font-Size="Normal"/>
<mobile:Label ID="LabelPlatform" Runat="server" Alignment="Center" Font-Size="Normal"/>
<mobile:Label ID="LabelBrowser" Runat="server" Alignment="Center" Font-Size="Normal"/>
<mobile:Label ID="LabelJpg" Runat="server" Alignment="Center" Font-Size="Normal"/>
<mobile:Label ID="LabelPng" Runat="server" Alignment="Center" Font-Size="Normal"/>
<mobile:Label ID="LabelGif" Runat="server" Alignment="Center" Font-Size="Normal"/>
</mobile:Form>
</body>
</html>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class M : System.Web.UI.MobileControls.MobilePage
{
protected void Page_Load(object sender, EventArgs e)
{
string strUserAgent = Request.UserAgent;
LabelManufacturer.Text = "Manufacturer : " + Request.Browser.MobileDeviceManufacturer;
LabelModel.Text = "Model : " + Request.Browser.MobileDeviceModel;
LabelScreen.Text = "Screen : " + Request.Browser.ScreenPixelsWidth.ToString() + " x " + Request.Browser.ScreenPixelsHeight.ToString();
//Apart from standard capability information provided by "Request.Browser object",
//.NETMobileAPI provides more detailed information about the device capabilities.
LabelPlatform.Text = "Platform : " + Mobile.Devices.MobileDevices.GetCapability(strUserAgent, "device_os");
LabelBrowser.Text = "Browser : " + Mobile.Devices.MobileDevices.GetCapability(strUserAgent, "mobile_browser");
LabelJpg.Text = "Jpg Image : " + Mobile.Devices.MobileDevices.GetCapability(strUserAgent, "jpg");
LabelPng.Text = "Png Image : " + Mobile.Devices.MobileDevices.GetCapability(strUserAgent, "png");
LabelGif.Text = "Gif Image : " + Mobile.Devices.MobileDevices.GetCapability(strUserAgent, "gif");
//Note: For more capabilities please refer to App_Data/Capabilities.xml file.
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)