locked
MVC Detect Mobile Device, e.g., iPhone and Android RRS feed

  • Question

  • User920388869 posted

    Good morning.

    How can you Detect when a Mobile Device, e.g., iPhone and Android, access your web site?

    I am using MVC 5, EF 6.1.1, Bootswatch v3.1.1, VS 2013.

    Any help would be greatly appreciated.

    Thank you.

    Sincerely,

    Mike

    Monday, January 5, 2015 9:51 AM

Answers

  • User724169276 posted

    try 51degrees.

    http://51degrees.codeplex.com/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 5, 2015 9:56 AM
  • User281315223 posted

    What type of device detection are you looking for?

    Some elements about the type of device that is accessing your site is available within the incoming Request collection (such as the UserAgent and Platform properties) however these can generally not be the most accurate approaches. If you want to detect if your browser is simply "mobile" based on it's size, that could be done through a very simply Javascript or jQuery call like :

    <script type="text/javascript">
        $(function(){
                // Do something if the window is less than 480px (e.g. mobile/small)
                if($(window).width() <= 480){
                      // Your code here.   
                } 
        });
    </script>

    If your concerns lie with it's appearance, then you might want to consider designing it so that it maintains a uniform look across all devices and platforms., you should consider using Responsive Design

    Consider using one of the many Responsive Design Frameworks that are out there for your site, such as the Twitter Bootstrap. Responsive design focuses on making your site easily usable and accessible from basically any resolution and devices available.

    These could fairly easily be integrated into a Web Forms or MVC application and would basically be all that you would need to use : 

    This would really eliminate having to distinguish between a mobile and traditional (desktop) CSS file for each of the pages within your website. The above articles are specific to integrating Bootstrap (one of the most popular Responsive Design frameworks out there) into your ASP.NET Applications.

    If you need actual Device Detection

    You may want to consider taking a look at 51Degree's "Foundation" project (also called the 51Degrees.Mobi project) , which greatly enhances the Mobile detection features available in .NET and is actually recommended by ASP.net as it provides better detection for more recent devices.

    You can read more about the Foundation project and download it here.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 5, 2015 10:02 AM

All replies

  • User724169276 posted

    try 51degrees.

    http://51degrees.codeplex.com/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 5, 2015 9:56 AM
  • User281315223 posted

    What type of device detection are you looking for?

    Some elements about the type of device that is accessing your site is available within the incoming Request collection (such as the UserAgent and Platform properties) however these can generally not be the most accurate approaches. If you want to detect if your browser is simply "mobile" based on it's size, that could be done through a very simply Javascript or jQuery call like :

    <script type="text/javascript">
        $(function(){
                // Do something if the window is less than 480px (e.g. mobile/small)
                if($(window).width() <= 480){
                      // Your code here.   
                } 
        });
    </script>

    If your concerns lie with it's appearance, then you might want to consider designing it so that it maintains a uniform look across all devices and platforms., you should consider using Responsive Design

    Consider using one of the many Responsive Design Frameworks that are out there for your site, such as the Twitter Bootstrap. Responsive design focuses on making your site easily usable and accessible from basically any resolution and devices available.

    These could fairly easily be integrated into a Web Forms or MVC application and would basically be all that you would need to use : 

    This would really eliminate having to distinguish between a mobile and traditional (desktop) CSS file for each of the pages within your website. The above articles are specific to integrating Bootstrap (one of the most popular Responsive Design frameworks out there) into your ASP.NET Applications.

    If you need actual Device Detection

    You may want to consider taking a look at 51Degree's "Foundation" project (also called the 51Degrees.Mobi project) , which greatly enhances the Mobile detection features available in .NET and is actually recommended by ASP.net as it provides better detection for more recent devices.

    You can read more about the Foundation project and download it here.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 5, 2015 10:02 AM
  • User920388869 posted

    Thanks to everyone for their help.

    Wednesday, January 7, 2015 11:34 AM