Get Device Type C# Asp.Net

 public static bool IsMobileBrowser()

    {

        bool IsMobileDevice = false;

        try

        {

            HttpContext context = HttpContext.Current;

            if (context.Request.UserAgent != null)

            {

                if ((context.Request.UserAgent.ToLower().Contains("mobile") || context.Request.UserAgent.ToLower().Contains("android")))

                {

                    //IsMobileDevice = true;

                    IsMobileDevice = IsTablet(context.Request.UserAgent.ToLower(), true);

                }

            }


        }

        catch (Exception ex)

        {

            throw ex;

        }

        return IsMobileDevice;

    }



    public static bool IsTablet(string userAgent, bool isMobile)

    {

        Regex r = new Regex("iphone|android|android 3.0|xoom|sch-i800|playbook|kindle|nexus|ipad|ipod|applewebkit");

        bool isTablet = r.IsMatch(userAgent) && isMobile;

        return isTablet;

    }


Comments

Popular posts from this blog

Uploading Image to Sql Server Image Datatype in asp.net using fileupload Control

Get Running Sum of Query SQL Query