Sadece kod C# BrowserDetect
public class BrowserDetect : Page
{
private string _useragent = "";
private string _httpaccept = "";
#region Fields - Detection Argument Values
//standardized values for detection arguments.
private const string DargsIphone = "iphone";
private const string DargsIpod = "ipod";
private const string DargsIpad = "ipad";
private const string DargsIphoneOrIpod = "iphoneoripod";
private const string DargsIos = "ios";
private const string DargsAndroid = "android";
private const string DargsAndroidPhone = "androidphone";
private const string DargsAndroidTablet = "androidtablet";
private const string DargsGoogleTv = "googletv";
private const string DargsWebKit = "webkit";
private const string DargsSymbianOS = "symbianos";
private const string DargsS60 = "series60";
private const string DargsWindowsPhone7 = "windowsphone7";
private const string DargsWindowsMobile = "windowsmobile";
private const string DargsBlackBerry = "blackberry";
private const string DargsBlackBerryWebkit = "blackberrywebkit";
private const string DargsPalmOS = "palmos";
private const string DargsPalmWebOS = "webos";
private const string DargsWebOSTablet = "webostablet";
private const string DargsSmartphone = "smartphone";
private const string DargsBrewDevice = "brew";
private const string DargsDangerHiptop = "dangerhiptop";
private const string DargsOperaMobile = "operamobile";
private const string DargsWapWml = "wapwml";
private const string DargsKindle = "kindle";
private const string DargsMobileQuick = "mobilequick";
private const string DargsTierTablet = "tiertablet";
private const string DargsTierIphone = "tieriphone";
private const string DargsTierRichCss = "tierrichcss";
private const string DargsTierOtherPhones = "tierotherphones";
private const string DargsTierDesktop = "tierdesktop";
#endregion Fields - Detection Argument Values
#region Fields - User Agent Keyword Values
//Initialize some initial smartphone private string private stringiables.
private readonly string _engineWebKit = "webkit".ToUpper();
private readonly string _deviceIphone = "iphone".ToUpper();
private readonly string _deviceIpod = "ipod".ToUpper();
private readonly string _deviceIpad = "ipad".ToUpper();
private readonly string _deviceMacPpc = "macintosh".ToUpper(); //Used for disambiguation
private readonly string _deviceAndroid = "android".ToUpper();
private readonly string _deviceGoogleTv = "googletv".ToUpper();
private readonly string _deviceHtcFlyer = "htc_flyer".ToUpper(); //HTC Flyer
private readonly string _deviceSymbian = "symbian".ToUpper();
private readonly string _deviceS60 = "series60".ToUpper();
private readonly string _deviceS70 = "series70".ToUpper();
private readonly string _deviceS80 = "series80".ToUpper();
private readonly string _deviceS90 = "series90".ToUpper();
private readonly string _deviceWinPhone7 = "windows phone os 7".ToUpper();
private readonly string _deviceWinMob = "windows ce".ToUpper();
private readonly string _deviceWindows = "windows".ToUpper();
private readonly string _deviceIeMob = "iemobile".ToUpper();
private readonly string _devicePpc = "ppc".ToUpper(); //Stands for PocketPC
private readonly string _enginePie = "wm5 pie".ToUpper(); //An old Windows Mobile
private readonly string _deviceBb = "blackberry".ToUpper();
private readonly string _vndRim = "vnd.rim".ToUpper(); //Detectable when BB devices emulate IE or Firefox
private readonly string _deviceBbStorm = "blackberry95".ToUpper(); //Storm 1 and 2
private readonly string _deviceBbBold = "blackberry97".ToUpper(); //Bold
private readonly string _deviceBbTour = "blackberry96".ToUpper(); //Tour
private readonly string _deviceBbCurve = "blackberry89".ToUpper(); //Curve2
private readonly string _deviceBbTorch = "blackberry 98".ToUpper(); //Torch
private readonly string _deviceBbPlaybook = "playbook".ToUpper(); //PlayBook tablet
private readonly string _devicePalm = "palm".ToUpper();
private readonly string _deviceWebOS = "webos".ToUpper(); //For Palm's line of WebOS devices
private readonly string _deviceWebOShp = "hpwos".ToUpper(); //For HP's line of WebOS devices
private readonly string _engineBlazer = "blazer".ToUpper(); //Old Palm
private readonly string _engineXiino = "xiino".ToUpper(); //Another old Palm
private readonly string _deviceKindle = "kindle".ToUpper(); //Amazon Kindle, eInk one.
private readonly string _deviceNuvifone = "nuvifone".ToUpper(); //Garmin Nuvifone
//Initialize private stringiables for mobile-specific content.
private readonly string _vndwap = "vnd.wap".ToUpper();
private readonly string _wml = "wml".ToUpper();
//Initialize private stringiables for other random devices and mobile browsers.
private readonly string _deviceTablet = "tablet".ToUpper(); //Generic term for slate and tablet devices
private readonly string _deviceBrew = "brew".ToUpper();
private readonly string _deviceDanger = "danger".ToUpper();
private readonly string _deviceHiptop = "hiptop".ToUpper();
private readonly string _devicePlaystation = "playstation".ToUpper();
private readonly string _deviceNintendoDs = "nitro".ToUpper();
private readonly string _deviceNintendo = "nintendo".ToUpper();
private readonly string _deviceWii = "wii".ToUpper();
private readonly string _deviceXbox = "xbox".ToUpper();
private readonly string _deviceArchos = "archos".ToUpper();
private readonly string _engineOpera = "opera".ToUpper(); //Popular browser
private readonly string _engineNetfront = "netfront".ToUpper(); //Common embedded OS browser
private readonly string _engineUpBrowser = "up.browser".ToUpper(); //common on some phones
private readonly string _engineOpenWeb = "openweb".ToUpper(); //Transcoding by OpenWave server
private readonly string _deviceMidp = "midp".ToUpper(); //a mobile Java technology
private readonly string _uplink = "up.link".ToUpper();
private readonly string _engineTelecaQ = "teleca q".ToUpper(); //a modern feature phone browser
private readonly string _devicePda = "pda".ToUpper(); //some devices report themselves as PDAs
private readonly string _mini = "mini".ToUpper(); //Some mobile browsers put "mini" in their names.
private readonly string _mobile = "mobile".ToUpper();
//Some mobile browsers put "mobile" in their user agent private strings.
private readonly string _mobi = "mobi".ToUpper(); //Some mobile browsers put "mobi" in their user agent private strings.
//Use Maemo, Tablet, and Linux to test for Nokia"s Internet Tablets.
private readonly string _maemo = "maemo".ToUpper();
private readonly string _linux = "linux".ToUpper();
private readonly string _qtembedded = "qt embedded".ToUpper(); //for Sony Mylo
private readonly string _mylocom2 = "com2".ToUpper(); //for Sony Mylo also
//In some UserAgents, the only clue is the manufacturer.
private readonly string _manuSonyEricsson = "sonyericsson".ToUpper();
private readonly string _manuericsson = "ericsson".ToUpper();
private readonly string _manuSamsung1 = "sec-sgh".ToUpper();
private readonly string _manuSony = "sony".ToUpper();
private readonly string _manuHtc = "htc".ToUpper(); //Popular Android and WinMo manufacturer
//In some UserAgents, the only clue is the operator.
private readonly string _svcDocomo = "docomo".ToUpper();
private readonly string _svcKddi = "kddi".ToUpper();
private readonly string _svcVodafone = "vodafone".ToUpper();
//Disambiguation strings.
private readonly string _disUpdate = "update".ToUpper(); //pda vs. update
#endregion Fields - User Agent Keyword Values
///
/// To instantiate a WebPage sub-class with built-in
/// mobile device detection delegates and events.
///
/*public BrowserDetect()
{
}*/
///
/// To run the device detection methods andd fire
/// any existing OnDetectXXX events.
///
public void FireEvents()
{
if (_useragent == "" && _httpaccept == "")
{
_useragent = (HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"] ?? "").ToUpper();
_httpaccept = (HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT"] ?? "").ToUpper();
}
#region Event Fire Methods
BrowserDetectArgs mda;
if (DetectIpod())
{
mda = new BrowserDetectArgs(DargsIpod);
if (OnDetectIpod != null)
{
OnDetectIpod(this, mda);
return;
}
}
if (DetectIpad())
{
mda = new BrowserDetectArgs(DargsIpad);
if (OnDetectIpad != null)
{
OnDetectIpad(this, mda);
return;
}
}
if (DetectIphone())
{
mda = new BrowserDetectArgs(DargsIphone);
if (OnDetectIphone != null)
{
OnDetectIphone(this, mda);
return;
}
}
if (DetectIphoneOrIpod())
{
mda = new BrowserDetectArgs(DargsIphoneOrIpod);
if (OnDetectDetectIPhoneOrIpod != null)
{
OnDetectDetectIPhoneOrIpod(this, mda);
return;
}
}
if (DetectIos())
{
mda = new BrowserDetectArgs(DargsIos);
if (OnDetectIos != null)
{
OnDetectIos(this, mda);
return;
}
}
if (DetectAndroid())
{
mda = new BrowserDetectArgs(DargsAndroid);
if (OnDetectAndroid != null)
{
OnDetectAndroid(this, mda);
return;
}
}
if (DetectAndroidPhone())
{
mda = new BrowserDetectArgs(DargsAndroidPhone);
if (OnDetectAndroidPhone != null)
{
OnDetectAndroidPhone(this, mda);
return;
}
}
if (DetectAndroidTablet())
{
mda = new BrowserDetectArgs(DargsAndroidTablet);
if (OnDetectAndroidTablet != null)
{
OnDetectAndroidTablet(this, mda);
return;
}
}
if (DetectGoogleTv())
{
mda = new BrowserDetectArgs(DargsGoogleTv);
if (OnDetectGoogleTv != null)
{
OnDetectGoogleTv(this, mda);
return;
}
}
if (DetectWebkit())
{
mda = new BrowserDetectArgs(DargsWebKit);
if (OnDetectWebkit != null)
{
OnDetectWebkit(this, mda);
return;
}
}
if (DetectS60OssBrowser())
{
mda = new BrowserDetectArgs(DargsS60);
if (OnDetectS60OssBrowser != null)
{
OnDetectS60OssBrowser(this, mda);
return;
}
}
if (DetectSymbianOS())
{
mda = new BrowserDetectArgs(DargsSymbianOS);
if (OnDetectSymbianOS != null)
{
OnDetectSymbianOS(this, mda);
return;
}
}
if (DetectWindowsPhone7())
{
mda = new BrowserDetectArgs(DargsWindowsPhone7);
if (OnDetectWindowsPhone7 != null)
{
OnDetectWindowsPhone7(this, mda);
return;
}
}
if (DetectWindowsMobile())
{
mda = new BrowserDetectArgs(DargsWindowsMobile);
if (OnDetectWindowsMobile != null)
{
OnDetectWindowsMobile(this, mda);
return;
}
}
if (DetectBlackBerry())
{
mda = new BrowserDetectArgs(DargsBlackBerry);
if (OnDetectBlackBerry != null)
{
OnDetectBlackBerry(this, mda);
return;
}
}
if (DetectBlackBerryWebKit())
{
mda = new BrowserDetectArgs(DargsBlackBerryWebkit);
if (OnDetectBlackBerryWebkit != null)
{
OnDetectBlackBerryWebkit(this, mda);
return;
}
}
if (DetectPalmOS())
{
mda = new BrowserDetectArgs(DargsPalmOS);
if (OnDetectPalmOS != null)
{
OnDetectPalmOS(this, mda);
return;
}
}
if (DetectPalmWebOS())
{
mda = new BrowserDetectArgs(DargsPalmWebOS);
if (OnDetectPalmWebOS != null)
{
OnDetectPalmWebOS(this, mda);
return;
}
}
if (DetectWebOSTablet())
{
mda = new BrowserDetectArgs(DargsWebOSTablet);
if (OnDetectWebOSTablet != null)
{
OnDetectWebOSTablet(this, mda);
return;
}
}
if (DetectSmartphone())
{
mda = new BrowserDetectArgs(DargsSmartphone);
if (OnDetectSmartphone != null)
{
OnDetectSmartphone(this, mda);
return;
}
}
if (DetectBrewDevice())
{
mda = new BrowserDetectArgs(DargsBrewDevice);
if (OnDetectBrewDevice != null)
{
OnDetectBrewDevice(this, mda);
return;
}
}
if (DetectDangerHiptop())
{
mda = new BrowserDetectArgs(DargsDangerHiptop);
if (OnDetectDangerHiptop != null)
{
OnDetectDangerHiptop(this, mda);
return;
}
}
if (DetectOperaMobile())
{
mda = new BrowserDetectArgs(DargsOperaMobile);
if (OnDetectOperaMobile != null)
{
OnDetectOperaMobile(this, mda);
return;
}
}
if (DetectWapWml())
{
mda = new BrowserDetectArgs(DargsWapWml);
if (OnDetectWapWml != null)
{
OnDetectWapWml(this, mda);
return;
}
}
if (DetectKindle())
{
mda = new BrowserDetectArgs(DargsKindle);
if (OnDetectKindle != null)
{
OnDetectKindle(this, mda);
return;
}
}
if (DetectMobileQuick())
{
mda = new BrowserDetectArgs(DargsMobileQuick);
if (OnDetectMobileQuick != null)
{
OnDetectMobileQuick(this, mda);
return;
}
}
if (DetectTierTablet())
{
mda = new BrowserDetectArgs(DargsTierTablet);
if (OnDetectTierTablet != null)
{
OnDetectTierTablet(this, mda);
return;
}
}
if (DetectTierIphone())
{
mda = new BrowserDetectArgs(DargsTierIphone);
if (OnDetectTierIphone != null)
{
OnDetectTierIphone(this, mda);
return;
}
}
if (DetectTierRichCss())
{
mda = new BrowserDetectArgs(DargsTierRichCss);
if (OnDetectTierRichCss != null)
{
OnDetectTierRichCss(this, mda);
return;
}
}
if (DetectTierOtherPhones())
{
mda = new BrowserDetectArgs(DargsTierOtherPhones);
if (OnDetectTierOtherPhones != null)
{
OnDetectTierOtherPhones(this, mda);
//return;
}
}
else
{
mda = new BrowserDetectArgs(DargsTierDesktop);
if (OnDetectTierDesktop != null)
{
OnDetectTierDesktop(this, mda);
//return;
}
}
#endregion Event Fire Methods
}
public class BrowserDetectArgs : EventArgs
{
public BrowserDetectArgs(string type)
{
Type = type;
}
public readonly string Type;
}
#region Mobile Device Detection Methods
//**************************
// Detects if the current device is an iPod Touch.
public bool DetectIpod()
{
return _useragent.IndexOf(_deviceIpod, StringComparison.Ordinal) != -1;
}
//Ipod delegate
public delegate void DetectIpodHandler(object page, BrowserDetectArgs args);
public event DetectIpodHandler OnDetectIpod;
//**************************
// Detects if the current device is an iPad tablet.
public bool DetectIpad()
{
return _useragent.IndexOf(_deviceIpad, StringComparison.Ordinal) != -1 && DetectWebkit();
}
//Ipod delegate
public delegate void DetectIpadHandler(object page, BrowserDetectArgs args);
public event DetectIpadHandler OnDetectIpad;
//**************************
// Detects if the current device is an iPhone.
public bool DetectIphone()
{
if (_useragent.IndexOf(_deviceIphone, StringComparison.Ordinal) != -1)
{
//The iPad and iPod touch say they're an iPhone! So let's disambiguate.
return !DetectIpad() && !DetectIpod();
}
return false;
}
//IPhone delegate
public delegate void DetectIphoneHandler(object page, BrowserDetectArgs args);
public event DetectIphoneHandler OnDetectIphone;
//**************************
// Detects if the current device is an iPhone or iPod Touch.
public bool DetectIphoneOrIpod()
{
//We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
return _useragent.IndexOf(_deviceIphone, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceIpod, StringComparison.Ordinal) != -1;
}
//IPhoneOrIpod delegate
public delegate void DetectIPhoneOrIpodHandler(object page, BrowserDetectArgs args);
public event DetectIPhoneOrIpodHandler OnDetectDetectIPhoneOrIpod;
//**************************
// Detects *any* iOS device: iPhone, iPod Touch, iPad.
public bool DetectIos()
{
return DetectIphoneOrIpod() || DetectIpad();
}
//Ios delegate
public delegate void DetectIosHandler(object page, BrowserDetectArgs args);
public event DetectIosHandler OnDetectIos;
//**************************
// Detects *any* Android OS-based device: phone, tablet, and multi-media player.
// Also detects Google TV.
public bool DetectAndroid()
{
if ((_useragent.IndexOf(_deviceAndroid, StringComparison.Ordinal) != -1) ||
DetectGoogleTv())
return true;
//Special check for the HTC Flyer 7" tablet. It should report here.
return _useragent.IndexOf(_deviceHtcFlyer, StringComparison.Ordinal) != -1;
}
//Android delegate
public delegate void DetectAndroidHandler(object page, BrowserDetectArgs args);
public event DetectAndroidHandler OnDetectAndroid;
//**************************
// Detects if the current device is a (small-ish) Android OS-based device
// used for calling and/or multi-media (like a Samsung Galaxy Player).
// Google says these devices will have 'Android' AND 'mobile' in user agent.
// Ignores tablets (Honeycomb and later).
public bool DetectAndroidPhone()
{
if (DetectAndroid() &&
(_useragent.IndexOf(_mobile, StringComparison.Ordinal) != -1))
return true;
//Special check for Android phones with Opera Mobile. They should report here.
if (DetectOperaAndroidPhone())
return true;
//Special check for the HTC Flyer 7" tablet. It should report here.
if (_useragent.IndexOf(_deviceHtcFlyer, StringComparison.Ordinal) != -1)
return true;
return false;
}
//Android Phone delegate
public delegate void DetectAndroidPhoneHandler(object page, BrowserDetectArgs args);
public event DetectAndroidPhoneHandler OnDetectAndroidPhone;
//**************************
// Detects if the current device is a (self-reported) Android tablet.
// Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
public bool DetectAndroidTablet()
{
//First, let's make sure we're on an Android device.
if (!DetectAndroid())
return false;
//Special check for Opera Android Phones. They should NOT report here.
if (DetectOperaMobile())
return false;
//Special check for the HTC Flyer 7" tablet. It should NOT report here.
if (_useragent.IndexOf(_deviceHtcFlyer, StringComparison.Ordinal) != -1)
return false;
//Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
return _useragent.IndexOf(_mobile, StringComparison.Ordinal) <= -1;
}
//Android Tablet delegate
public delegate void DetectAndroidTabletHandler(object page, BrowserDetectArgs args);
public event DetectAndroidTabletHandler OnDetectAndroidTablet;
//**************************
// Detects if the current device is a GoogleTV device.
public bool DetectGoogleTv()
{
if (_useragent.IndexOf(_deviceGoogleTv, StringComparison.Ordinal) != -1)
return true;
return false;
}
//GoogleTV delegate
public delegate void DetectGoogleTvHandler(object page, BrowserDetectArgs args);
public event DetectGoogleTvHandler OnDetectGoogleTv;
//**************************
// Detects if the current device is an Android OS-based device and
// the browser is based on WebKit.
public bool DetectAndroidWebKit()
{
if (DetectAndroid() && DetectWebkit())
return true;
return false;
}
//**************************
// Detects if the current browser is based on WebKit.
public bool DetectWebkit()
{
return _useragent.IndexOf(_engineWebKit, StringComparison.Ordinal) != -1;
}
//Webkit delegate
public delegate void DetectWebkitHandler(object page, BrowserDetectArgs args);
public event DetectWebkitHandler OnDetectWebkit;
// Detects if the current browser is the Nokia S60 Open Source Browser.
public bool DetectS60OssBrowser()
{
//First, test for WebKit, then make sure it's either Symbian or S60.
if (DetectWebkit())
{
return _useragent.IndexOf(_deviceSymbian, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceS60, StringComparison.Ordinal) != -1;
}
return false;
}
//S60OssBrowser delegate
public delegate void DetectS60OssBrowserHandler(object page, BrowserDetectArgs args);
public event DetectS60OssBrowserHandler OnDetectS60OssBrowser;
// Detects if the current device is any Symbian OS-based device,
// including older S60, Series 70, Series 80, Series 90, and UIQ,
// or other browsers running on these devices.
public bool DetectSymbianOS()
{
return _useragent.IndexOf(_deviceSymbian, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceS60, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceS70, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceS80, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceS90, StringComparison.Ordinal) != -1;
}
//SymbianOS delegate
public delegate void DetectSymbianOSHandler(object page, BrowserDetectArgs args);
public event DetectSymbianOSHandler OnDetectSymbianOS;
// Detects if the current browser is a
// Windows Phone 7 device.
public bool DetectWindowsPhone7()
{
if (_useragent.IndexOf(_deviceWinPhone7, StringComparison.Ordinal) != -1)
return true;
return false;
}
//WindowsPhone7 delegate
public delegate void DetectWindowsPhone7Handler(object page, BrowserDetectArgs args);
public event DetectWindowsPhone7Handler OnDetectWindowsPhone7;
//**************************
// Detects if the current browser is a Windows Mobile device.
// Excludes Windows Phone 7 devices.
// Focuses on Windows Mobile 6.xx and earlier.
public bool DetectWindowsMobile()
{
//Exclude new Windows Phone 7.
if (DetectWindowsPhone7())
return false;
//Most devices use 'Windows CE', but some report 'iemobile'
// and some older ones report as 'PIE' for Pocket IE.
if (_useragent.IndexOf(_deviceWinMob, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceIeMob, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_enginePie, StringComparison.Ordinal) != -1)
return true;
//Test for Windows Mobile PPC but not old Macintosh PowerPC.
if (_useragent.IndexOf(_devicePpc, StringComparison.Ordinal) != -1 &&
_useragent.IndexOf(_deviceMacPpc, StringComparison.Ordinal) == -1)
//!(useragent.IndexOf(deviceMacPpc) != -1))
return true;
//Test for certain Windwos Mobile-based HTC devices.
if (_useragent.IndexOf(_manuHtc, StringComparison.Ordinal) != -1 &&
_useragent.IndexOf(_deviceWindows, StringComparison.Ordinal) != -1)
return true;
return DetectWapWml() &&
_useragent.IndexOf(_deviceWindows, StringComparison.Ordinal) != -1;
}
//WindowsMobile delegate
public delegate void DetectWindowsMobileHandler(object page, BrowserDetectArgs args);
public event DetectWindowsMobileHandler OnDetectWindowsMobile;
//**************************
// Detects if the current browser is any BlackBerry device.
// Includes the PlayBook.
public bool DetectBlackBerry()
{
if (_useragent.IndexOf(_deviceBb, StringComparison.Ordinal) != -1)
return true;
return _httpaccept.IndexOf(_vndRim, StringComparison.Ordinal) != -1;
}
//BlackBerry delegate
public delegate void DetectBlackBerryHandler(object page, BrowserDetectArgs args);
public event DetectBlackBerryHandler OnDetectBlackBerry;
//**************************
// Detects if the current browser is on a BlackBerry tablet device.
// Example: PlayBook
public bool DetectBlackBerryTablet()
{
return _useragent.IndexOf(_deviceBbPlaybook, StringComparison.Ordinal) != -1;
}
//**************************
// Detects if the current browser is a BlackBerry device AND uses a
// WebKit-based browser. These are signatures for the new BlackBerry OS 6.
// Examples: Torch. Includes the Playbook.
public bool DetectBlackBerryWebKit()
{
return DetectBlackBerry() && DetectWebkit();
}
//BlackBerry Webkit delegate
public delegate void DetectBlackBerryWebkitHandler(object page, BrowserDetectArgs args);
public event DetectBlackBerryWebkitHandler OnDetectBlackBerryWebkit;
//**************************
// Detects if the current browser is a BlackBerry Touch
// device, such as the Storm or Touch. Excludes the Playbook.
public bool DetectBlackBerryTouch()
{
return DetectBlackBerry() &&
(_useragent.IndexOf(_deviceBbStorm, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceBbTorch, StringComparison.Ordinal) != -1);
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has a more capable recent browser. Excludes the Playbook.
// Examples, Storm, Bold, Tour, Curve2
public bool DetectBlackBerryHigh()
{
//Disambiguate for BlackBerry OS 6 (WebKit) browser
if (DetectBlackBerryWebKit())
return false;
if (DetectBlackBerry())
{
return DetectBlackBerryTouch() ||
_useragent.IndexOf(_deviceBbBold, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceBbTour, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceBbCurve, StringComparison.Ordinal) != -1;
}
return false;
}
//**************************
// Detects if the current browser is a BlackBerry device AND
// has an older, less capable browser.
// Examples: Pearl, 8800, Curve1.
public bool DetectBlackBerryLow()
{
if (DetectBlackBerry())
{
//Assume that if it's not in the High tier, then it's Low.
return !DetectBlackBerryHigh() && !DetectBlackBerryWebKit();
}
return false;
}
//**************************
// Detects if the current browser is on a PalmOS device.
public bool DetectPalmOS()
{
//Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
if (_useragent.IndexOf(_devicePalm, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_engineBlazer, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_engineXiino, StringComparison.Ordinal) != -1)
{
//Make sure it's not WebOS first
return !DetectPalmWebOS();
}
return false;
}
//PalmOS delegate
public delegate void DetectPalmOSHandler(object page, BrowserDetectArgs args);
public event DetectPalmOSHandler OnDetectPalmOS;
//**************************
// Detects if the current browser is on a Palm device
// running the new WebOS.
public bool DetectPalmWebOS()
{
return _useragent.IndexOf(_deviceWebOS, StringComparison.Ordinal) != -1;
}
//PalmWebOS delegate
public delegate void DetectPalmWebOSHandler(object page, BrowserDetectArgs args);
public event DetectPalmWebOSHandler OnDetectPalmWebOS;
//**************************
// Detects if the current browser is on an HP tablet running WebOS.
public bool DetectWebOSTablet()
{
return _useragent.IndexOf(_deviceWebOShp, StringComparison.Ordinal) != -1 &&
_useragent.IndexOf(_deviceTablet, StringComparison.Ordinal) != -1;
}
//WebOS tablet delegate
public delegate void DetectWebOSTabletHandler(object page, BrowserDetectArgs args);
public event DetectWebOSTabletHandler OnDetectWebOSTablet;
//**************************
// Detects if the current browser is a
// Garmin Nuvifone.
public bool DetectGarminNuvifone()
{
return _useragent.IndexOf(_deviceNuvifone, StringComparison.Ordinal) != -1;
}
//**************************
// Check to see whether the device is any device
// in the 'smartphone' category.
public bool DetectSmartphone()
{
if (DetectIphoneOrIpod() ||
DetectAndroidPhone() ||
DetectS60OssBrowser() ||
DetectSymbianOS() ||
DetectWindowsMobile() ||
DetectWindowsPhone7() ||
DetectBlackBerry() ||
DetectPalmWebOS() ||
DetectPalmOS() ||
DetectGarminNuvifone())
return true;
return false;
}
//DetectSmartphone delegate
public delegate void DetectSmartphoneHandler(object page, BrowserDetectArgs args);
public event DetectSmartphoneHandler OnDetectSmartphone;
//**************************
// Detects whether the device is a Brew-powered device.
public bool DetectBrewDevice()
{
if (_useragent.IndexOf(_deviceBrew, StringComparison.Ordinal) != -1)
return true;
return false;
}
//BrewDevice delegate
public delegate void DetectBrewDeviceHandler(object page, BrowserDetectArgs args);
public event DetectBrewDeviceHandler OnDetectBrewDevice;
//**************************
// Detects the Danger Hiptop device.
public bool DetectDangerHiptop()
{
return _useragent.IndexOf(_deviceDanger, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceHiptop, StringComparison.Ordinal) != -1;
}
//DangerHiptop delegate
public delegate void DetectDangerHiptopHandler(object page, BrowserDetectArgs args);
public event DetectDangerHiptopHandler OnDetectDangerHiptop;
//**************************
// Detects if the current browser is Opera Mobile or Mini.
public bool DetectOperaMobile()
{
if (_useragent.IndexOf(_engineOpera, StringComparison.Ordinal) != -1)
{
return (_useragent.IndexOf(_mini, StringComparison.Ordinal) != -1) ||
(_useragent.IndexOf(_mobi, StringComparison.Ordinal) != -1);
}
return false;
}
//Opera Mobile delegate
public delegate void DetectOperaMobileHandler(object page, BrowserDetectArgs args);
public event DetectOperaMobileHandler OnDetectOperaMobile;
//**************************
// Detects if the current browser is Opera Mobile
// running on an Android phone.
public bool DetectOperaAndroidPhone()
{
return (_useragent.IndexOf(_engineOpera, StringComparison.Ordinal) != -1) &&
(_useragent.IndexOf(_deviceAndroid, StringComparison.Ordinal) != -1) &&
(_useragent.IndexOf(_mobi, StringComparison.Ordinal) != -1);
}
// Detects if the current browser is Opera Mobile
// running on an Android tablet.
public bool DetectOperaAndroidTablet()
{
return (_useragent.IndexOf(_engineOpera, StringComparison.Ordinal) != -1) &&
(_useragent.IndexOf(_deviceAndroid, StringComparison.Ordinal) != -1) &&
(_useragent.IndexOf(_deviceTablet, StringComparison.Ordinal) != -1);
}
//**************************
// Detects whether the device supports WAP or WML.
public bool DetectWapWml()
{
if (_httpaccept.IndexOf(_vndwap, StringComparison.Ordinal) != -1 ||
_httpaccept.IndexOf(_wml, StringComparison.Ordinal) != -1)
return true;
return false;
}
//WapWml delegate
public delegate void DetectWapWmlHandler(object page, BrowserDetectArgs args);
public event DetectWapWmlHandler OnDetectWapWml;
//**************************
// Detects if the current device is an Amazon Kindle.
public bool DetectKindle()
{
if (_useragent.IndexOf(_deviceKindle, StringComparison.Ordinal) != -1)
return true;
return false;
}
//Kindle delegate
public delegate void DetectKindleHandler(object page, BrowserDetectArgs args);
public event DetectKindleHandler OnDetectKindle;
//**************************
// Detects if the current device is a mobile device.
// This method catches most of the popular modern devices.
// Excludes Apple iPads and other modern tablets.
public bool DetectMobileQuick()
{
//Let's exclude tablets
if (DetectTierTablet())
return false;
//Most mobile browsing is done on smartphones
if (DetectSmartphone())
return true;
if (DetectWapWml() ||
DetectBrewDevice() ||
DetectOperaMobile())
return true;
if ((_useragent.IndexOf(_engineNetfront, StringComparison.Ordinal) != -1) ||
(_useragent.IndexOf(_engineUpBrowser, StringComparison.Ordinal) != -1) ||
(_useragent.IndexOf(_engineOpenWeb, StringComparison.Ordinal) != -1))
return true;
if (DetectDangerHiptop() ||
DetectMidpCapable() ||
DetectMaemoTablet() ||
DetectArchos())
return true;
if ((_useragent.IndexOf(_devicePda, StringComparison.Ordinal) != -1) &&
(_useragent.IndexOf(_disUpdate, StringComparison.Ordinal) < 0)) //no index found
return true;
return _useragent.IndexOf(_mobile, StringComparison.Ordinal) != -1;
}
//DetectMobileQuick delegate
public delegate void DetectMobileQuickHandler(object page, BrowserDetectArgs args);
public event DetectMobileQuickHandler OnDetectMobileQuick;
//**************************
// Detects if the current device is a Sony Playstation.
public bool DetectSonyPlaystation()
{
return _useragent.IndexOf(_devicePlaystation, StringComparison.Ordinal) != -1;
}
//**************************
// Detects if the current device is a Nintendo game device.
public bool DetectNintendo()
{
if (_useragent.IndexOf(_deviceNintendo, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceWii, StringComparison.Ordinal) != -1 ||
_useragent.IndexOf(_deviceNintendoDs, StringComparison.Ordinal) != -1)
return true;
return false;
}
//**************************
// Detects if the current device is a Microsoft Xbox.
public bool DetectXbox()
{
return _useragent.IndexOf(_deviceXbox, StringComparison.Ordinal) != -1;
}
//**************************
// Detects if the current device is an Internet-capable game console.
public bool DetectGameConsole()
{
if (DetectSonyPlaystation())
return true;
return DetectNintendo() || DetectXbox();
}
//**************************
// Detects if the current device supports MIDP, a mobile Java technology.
public bool DetectMidpCapable()
{
if (_useragent.IndexOf(_deviceMidp, StringComparison.Ordinal) != -1 ||
_httpaccept.IndexOf(_deviceMidp, StringComparison.Ordinal) != -1)
return true;
return false;
}
//**************************
// Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
public bool DetectMaemoTablet()
{
if (_useragent.IndexOf(_maemo, StringComparison.Ordinal) != -1)
return true;
//For Nokia N810, must be Linux + Tablet, or else it could be something else.
if (_useragent.IndexOf(_linux, StringComparison.Ordinal) != -1 &&
_useragent.IndexOf(_deviceTablet, StringComparison.Ordinal) != -1 &&
!DetectWebOSTablet() &&
!DetectAndroid())
return true;
return false;
}
//**************************
// Detects if the current device is an Archos media player/Internet tablet.
public bool DetectArchos()
{
if (_useragent.IndexOf(_deviceArchos, StringComparison.Ordinal) != -1)
return true;
return false;
}
//**************************
// Detects if the current browser is a Sony Mylo device.
public bool DetectSonyMylo()
{
if (_useragent.IndexOf(_manuSony, StringComparison.Ordinal) != -1)
{
if ((_useragent.IndexOf(_qtembedded, StringComparison.Ordinal) != -1) ||
(_useragent.IndexOf(_mylocom2, StringComparison.Ordinal) != -1))
{
return true;
}
return false;
}
return false;
}
//**************************
// The longer and more thorough way to detect for a mobile device.
// Will probably detect most feature phones,
// smartphone-class devices, Internet Tablets,
// Internet-enabled game consoles, etc.
// This ought to catch a lot of the more obscure and older devices, also --
// but no promises on thoroughness!
public bool DetectMobileLong()
{
if (DetectMobileQuick())
return true;
if (DetectGameConsole() ||
DetectSonyMylo())
return true;
//Detect older phones from certain manufacturers and operators.
if (_useragent.IndexOf(_uplink, StringComparison.Ordinal) != -1)
return true;
if (_useragent.IndexOf(_manuSonyEricsson, StringComparison.Ordinal) != -1)
return true;
if (_useragent.IndexOf(_manuericsson, StringComparison.Ordinal) != -1)
return true;
if (_useragent.IndexOf(_manuSamsung1, StringComparison.Ordinal) != -1)
return true;
if (_useragent.IndexOf(_svcDocomo, StringComparison.Ordinal) != -1)
return true;
if (_useragent.IndexOf(_svcKddi, StringComparison.Ordinal) != -1)
return true;
if (_useragent.IndexOf(_svcVodafone, StringComparison.Ordinal) != -1)
return true;
return false;
}
//*****************************
// For Mobile Web Site Design
//*****************************
//**************************
// The quick way to detect for a tier of devices.
// This method detects for the new generation of
// HTML 5 capable, larger screen tablets.
// Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
public bool DetectTierTablet()
{
if (DetectIpad()
|| DetectAndroidTablet()
|| DetectBlackBerryTablet()
|| DetectWebOSTablet())
return true;
return false;
}
//DetectTierTablet delegate
public delegate void DetectTierTabletHandler(object page, BrowserDetectArgs args);
public event DetectTierTabletHandler OnDetectTierTablet;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which can
// display iPhone-optimized web content.
// Includes iPhone, iPod Touch, Android, etc.
public bool DetectTierIphone()
{
if (DetectIphoneOrIpod() ||
DetectAndroidPhone() ||
(DetectBlackBerryWebKit() &&
DetectBlackBerryTouch()) ||
DetectPalmWebOS() ||
DetectGarminNuvifone())
return true;
return false;
}
//DetectTierIphone delegate
public delegate void DetectTierIphoneHandler(object page, BrowserDetectArgs args);
public event DetectTierIphoneHandler OnDetectTierIphone;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for devices which are likely to be capable
// of viewing CSS content optimized for the iPhone,
// but may not necessarily support JavaScript.
// Excludes all iPhone Tier devices.
public bool DetectTierRichCss()
{
if (DetectMobileQuick())
{
if (DetectTierIphone())
return false;
if (DetectWebkit() ||
DetectS60OssBrowser())
return true;
if (DetectBlackBerryHigh())
return true;
//WP7's IE-7-based browser isn't good enough for iPhone Tier.
if (DetectWindowsPhone7())
return true;
if (DetectWindowsMobile())
return true;
return _useragent.IndexOf(_engineTelecaQ, StringComparison.Ordinal) != -1;
}
return false;
}
//DetectTierRichCss delegate
public delegate void DetectTierRichCssHandler(object page, BrowserDetectArgs args);
public event DetectTierRichCssHandler OnDetectTierRichCss;
//**************************
// The quick way to detect for a tier of devices.
// This method detects for all other types of phones,
// but excludes the iPhone and Smartphone Tier devices.
public bool DetectTierOtherPhones()
{
if (DetectMobileLong())
{
//Exclude devices in the other 2 categories
return !DetectTierIphone() && !DetectTierRichCss();
}
return false;
}
//DetectTierOtherPhones delegate
public delegate void DetectTierOtherPhonesHandler(object page, BrowserDetectArgs args);
public event DetectTierOtherPhonesHandler OnDetectTierOtherPhones;
public delegate void DetectTierDesktopHandler(object page, BrowserDetectArgs args);
public event DetectTierDesktopHandler OnDetectTierDesktop;
#endregion
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_useragent = Request.ServerVariables["HTTP_USER_AGENT"].ToUpper();
_httpaccept = Request.ServerVariables["HTTP_ACCEPT"].ToUpper();
}
}




0 yorum:
Yorum Gönder