Example #1
0
        public static bool isMobile(bool AllowCookieOverride)
        {
            if (AppLogic.IsAdminSite == true || !MobilePlatform.IsEnabled)
            {
                return(false);
            }

            if (AllowCookieOverride && CommonLogic.CookieCanBeDangerousContent(ForceMobileCookie, false).Length > 0)
            {
                return(CommonLogic.CookieBool(ForceMobileCookie));
            }

            //example userAgentString
            //Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16
            string userAgentString    = CommonLogic.ServerVariables("HTTP_USER_AGENT").ToUpperInvariant();
            string httpAccept         = CommonLogic.ServerVariables("HTTP_ACCEPT");
            string xProfile           = CommonLogic.ServerVariables("HTTP_X_PROFILE");
            string httpProfile        = CommonLogic.ServerVariables("HTTP_PROFILE");
            string userAgentList      = MobilePlatform.UserAgentList ?? String.Empty;      //android, palm, motorola, etc
            string shortUserAgentList = MobilePlatform.ShortUserAgentList ?? String.Empty; //moto, noki, sany, etc

            if (!MobilePlatform.ShowMobileOniPad && userAgentString.Contains("IPAD;"))
            {
                return(false);
            }

            if (httpAccept.Contains("application/vnd.wap.xhtml+xml") || xProfile.Length > 0 || httpProfile.Length > 0)
            {
                SetMobileContextItem(true);
                return(true);
            }

            //check for most common mobile
            string[] agentList = userAgentList.ToUpperInvariant().Split(',');
            //check if userAgentString contains any of our agents in the agentList
            if (agentList.Any(userAgentString.Contains))
            {
                SetMobileContextItem(true);
                return(true);
            }

            //check for mobile that slipped through with longer list of substrings
            string[] shortAgentList = shortUserAgentList.ToUpperInvariant().Split(',');
            //check if userAgentString contains any of our agents in the shortAgentList
            if (shortAgentList.Any(userAgentString.Contains))
            {
                SetMobileContextItem(true);
                return(true);
            }

            return(false);
        }