Example #1
0
    /// <summary>
    /// Returns URL specified by automatic logic
    /// </summary>
    /// <param name="userAgentEnum">User agent enum type</param>
    /// <param name="smallUrl">Small URL</param>
    /// <param name="largeUrl">Large URL</param>
    private string GetAutomaticDeviceUrl(UserAgentEnum userAgentEnum, string smallUrl, string largeUrl)
    {
        switch (userAgentEnum)
        {
        case UserAgentEnum.IPad:
            return(largeUrl);

        default:
            return(smallUrl);
        }
    }
Example #2
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            // Trim blank characters
            string rawSmallDeviceURL = SmallDeviceRedirectionURL.Trim();
            string rawLargeDeviceURL = LargeDeviceRedirectionURL.Trim();

            // Get redirect cookie
            string redirected = CookieHelper.GetValue(CookieName.MobileRedirected);

            if ((AlwaysRedirect || String.IsNullOrEmpty(redirected)) && PortalContext.ViewMode.IsLiveSite())
            {
                string redirectUrl = null;

                // Get user agent name or user agent string
                string userAgent = BrowserHelper.GetUserAgent();

                if (!string.IsNullOrEmpty(userAgent))
                {
                    UserAgentEnum userAgentEnum = GetUserAgentName(userAgent);

                    if (userAgentEnum != UserAgentEnum.Unknown)
                    {
                        redirectUrl = GetRedirectUrl(userAgent, userAgentEnum, rawSmallDeviceURL, rawLargeDeviceURL);
                    }
                    else
                    {
                        redirectUrl = CheckUsersRedirection(userAgent, rawSmallDeviceURL, rawLargeDeviceURL);
                    }

                    // Check if some address is specified
                    if (!string.IsNullOrEmpty(redirectUrl))
                    {
                        string newURL = URLHelper.ResolveUrl(redirectUrl);

                        newURL = EnsureQueryValues(newURL);

                        // If current URL is same as set, no redirection is done
                        if ((!RequestContext.CurrentURL.EqualsCSafe(newURL, true)) && (!URLHelper.GetAbsoluteUrl(RequestContext.CurrentURL).EqualsCSafe(newURL, true)))
                        {
                            // Set redirected cookie
                            CookieHelper.SetValue(CookieName.MobileRedirected, "true", DateTimeHelper.ZERO_TIME);
                            URLHelper.ResponseRedirect(newURL);
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Returns redirect url for specified user agent and redirection settings.
    /// </summary>
    protected string GetRedirectUrl(string redirectSettings, string userAgent, UserAgentEnum userAgentEnum, string smallUrl, string largeUrl)
    {
        switch (redirectSettings)
        {
        case SETTINGS_DEVICE_AUTOMATIC:
            string url = CheckUsersRedirection(userAgent, smallUrl, largeUrl);

            if (!string.IsNullOrEmpty(url))
            {
                return(url);
            }
            else
            {
                switch (userAgentEnum)
                {
                case UserAgentEnum.BlackBerry:
                    return(smallUrl);

                case UserAgentEnum.IPhone:
                    return(largeUrl);

                case UserAgentEnum.IPad:
                    return(largeUrl);

                case UserAgentEnum.Nokia:
                    return(largeUrl);

                case UserAgentEnum.Android:
                    return(largeUrl);

                default:
                    return(smallUrl);
                }
            }

        case SETTINGS_DEVICE_SMALL:
            return(smallUrl);

        case SETTINGS_DEVICE_LARGE:
            return(largeUrl);

        default:
            return(string.Empty);
        }
    }
Example #4
0
    /// <summary>
    /// Returns redirect URL for specified user agent and redirection settings.
    /// </summary>
    protected string GetRedirectUrl(string userAgent, UserAgentEnum userAgentEnum, string smallUrl, string largeUrl)
    {
        switch (GetRedirectSettings(userAgentEnum))
        {
        case SETTINGS_DEVICE_AUTOMATIC:
            // Try get user defined redirect
            string url = CheckUsersRedirection(userAgent, smallUrl, largeUrl);
            // Return user defined redirect or URL defined by device type settings
            return((!string.IsNullOrEmpty(url)) ? url : GetAutomaticDeviceUrl(userAgentEnum, smallUrl, largeUrl));

        case SETTINGS_DEVICE_SMALL:
            return(smallUrl);

        case SETTINGS_DEVICE_LARGE:
            return(largeUrl);

        default:
            return(string.Empty);
        }
    }
Example #5
0
    /// <summary>
    /// Gets the redirect settings for specific user agent type
    /// </summary>
    /// <param name="userAgentEnum">User agent type</param>
    private string GetRedirectSettings(UserAgentEnum userAgentEnum)
    {
        switch (userAgentEnum)
        {
        case UserAgentEnum.BlackBerry:
            return(RedirectBlackBerry);

        case UserAgentEnum.IPhone:
            return(RedirectIPhone);

        case UserAgentEnum.IPad:
            return(RedirectIPad);

        case UserAgentEnum.Nokia:
            return(RedirectNokia);

        case UserAgentEnum.Android:
            return(RedirectAndroid);
        }
        return(String.Empty);
    }
Example #6
0
        public HttpBrowser(UserAgentEnum userAgent)
        {
            switch (userAgent)
            {
                case UserAgentEnum.Chrome:
                    UserAgent = ChromeUserAgent;
                    break;
                case UserAgentEnum.Firefox:
                    UserAgent = FirefoxUserAgent;
                    break;
                case UserAgentEnum.InternetExplorer:
                    UserAgent = InternetExplorerUserAgent;
                    break;
                case UserAgentEnum.IPhone:
                    UserAgent = IPhoneUserAgent;
                    break;
                default:
                    UserAgent = FirefoxUserAgent;
                    break;
            }

            Cookies = new CookieContainer();
        }
    /// <summary>
    /// Returns redirect url for specified user agent and redirection settings.
    /// </summary>
    protected string GetRedirectUrl(string redirectSettings, string userAgent, UserAgentEnum userAgentEnum, string smallUrl, string largeUrl)
    {
        switch (redirectSettings)
        {
            case SETTINGS_DEVICE_AUTOMATIC:
                string url = CheckUsersRedirection(userAgent, smallUrl, largeUrl);

                if (!string.IsNullOrEmpty(url))
                {
                    return url;
                }
                else
                {
                    switch (userAgentEnum)
                    {
                        case UserAgentEnum.BlackBerry:
                            return smallUrl;

                        case UserAgentEnum.IPhone:
                            return largeUrl;

                        case UserAgentEnum.IPad:
                            return largeUrl;

                        case UserAgentEnum.Nokia:
                            return largeUrl;

                        case UserAgentEnum.Android:
                            return largeUrl;

                        default:
                            return smallUrl;
                    }
                }

            case SETTINGS_DEVICE_SMALL:
                return smallUrl;

            case SETTINGS_DEVICE_LARGE:
                return largeUrl;

            default:
                return string.Empty;
        }
    }
    /// <summary>
    /// Gets the redirect settings for specific user agent type
    /// </summary>
    /// <param name="userAgentEnum">User agent type</param>
    private string GetRedirectSettings(UserAgentEnum userAgentEnum)
    {
        switch (userAgentEnum)
        {
            case UserAgentEnum.BlackBerry:
                return RedirectBlackBerry;

            case UserAgentEnum.IPhone:
                return RedirectIPhone;

            case UserAgentEnum.IPad:
                return RedirectIPad;

            case UserAgentEnum.Nokia:
                return RedirectNokia;

            case UserAgentEnum.Android:
                return RedirectAndroid;
        }
        return String.Empty;
    }
    /// <summary>
    /// Returns URL specified by automatic logic
    /// </summary>
    /// <param name="userAgentEnum">User agent enum type</param>
    /// <param name="smallUrl">Small URL</param>
    /// <param name="largeUrl">Large URL</param>
    private string GetAutomaticDeviceUrl(UserAgentEnum userAgentEnum, string smallUrl, string largeUrl)
    {
        switch (userAgentEnum)
        {
            case UserAgentEnum.IPad:
                return largeUrl;

            default:
                return smallUrl;
        }
    }
    /// <summary>
    /// Returns redirect URL for specified user agent and redirection settings.
    /// </summary>
    protected string GetRedirectUrl(string userAgent, UserAgentEnum userAgentEnum, string smallUrl, string largeUrl)
    {
        switch (GetRedirectSettings(userAgentEnum))
        {
            case SETTINGS_DEVICE_AUTOMATIC:
                // Try get user defined redirect
                string url = CheckUsersRedirection(userAgent, smallUrl, largeUrl);
                // Return user defined redirect or URL defined by device type settings
                return (!string.IsNullOrEmpty(url)) ? url : GetAutomaticDeviceUrl(userAgentEnum, smallUrl, largeUrl);

            case SETTINGS_DEVICE_SMALL:
                return smallUrl;

            case SETTINGS_DEVICE_LARGE:
                return largeUrl;

            default:
                return string.Empty;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (!StopProcessing)
        {
            // Trim blank characters
            string rawSmallDeviceURL = SmallDeviceRedirectionURL.Trim();
            string rawLargeDeviceURL = LargeDeviceRedirectionURL.Trim();

            // Get redirect cookie
            string redirected = CookieHelper.GetValue("CMSMobileRedirected");

            if ((AlwaysRedirect || String.IsNullOrEmpty(redirected)) && (CMSContext.ViewMode == ViewModeEnum.LiveSite))
            {
                string redirectUrl = null;

                // Get user agent name or user agent string
                string userAgent = BrowserHelper.GetUserAgent();

                if (!string.IsNullOrEmpty(userAgent))
                {
                    UserAgentEnum userAgentEnum    = GetUserAgentName(userAgent);
                    string        redirectSettings = null;
                    switch (userAgentEnum)
                    {
                    case UserAgentEnum.BlackBerry:
                        redirectSettings = RedirectBlackBerry;
                        break;

                    case UserAgentEnum.IPhone:
                        redirectSettings = RedirectIPhone;
                        break;

                    case UserAgentEnum.IPad:
                        redirectSettings = RedirectIPad;
                        break;

                    case UserAgentEnum.Nokia:
                        redirectSettings = RedirectNokia;
                        break;

                    case UserAgentEnum.Android:
                        redirectSettings = RedirectAndroid;
                        break;
                    }

                    if (redirectSettings != null)
                    {
                        redirectUrl = GetRedirectUrl(redirectSettings, userAgent, userAgentEnum, rawSmallDeviceURL, rawLargeDeviceURL);
                    }
                    else
                    {
                        redirectUrl = CheckUsersRedirection(userAgent, rawSmallDeviceURL, rawLargeDeviceURL);
                    }
                }

                // Check if some address is specified
                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    string newURL = URLHelper.ResolveUrl(redirectUrl);

                    // If current URL is same as set, no redirection is done
                    if ((URLHelper.CurrentURL != newURL) && (URLHelper.GetAbsoluteUrl(URLHelper.CurrentURL) != newURL))
                    {
                        // Set redirected cookie
                        CookieHelper.SetValue("CMSMobileRedirected", "true", DateTimeHelper.ZERO_TIME);
                        URLHelper.ResponseRedirect(newURL);
                    }
                }
            }
        }
    }