Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

check the request comes from which operating system used by user in asp net core

string device = getOSInfo();

public String getOSInfo()
{
    var ua = Request.UserAgent;

    if (ua.Contains("Android"))
        return string.Format("Android {0}", GetMobileVersion(ua, "Android"));

    if (ua.Contains("iPad"))
        return string.Format("iPad OS {0}", GetMobileVersion(ua, "OS"));

    if (ua.Contains("iPhone"))
        return string.Format("iPhone OS {0}", GetMobileVersion(ua, "OS"));

    if (ua.Contains("Linux") && ua.Contains("KFAPWI"))
        return "Kindle Fire";

    if (ua.Contains("RIM Tablet") || (ua.Contains("BB") && ua.Contains("Mobile")))
        return "Black Berry";

    if (ua.Contains("Windows Phone"))
        return string.Format("Windows Phone {0}", GetMobileVersion(ua, "Windows Phone"));

    if (ua.Contains("Mac OS"))
        return "Mac OS";

    if (ua.Contains("Windows NT 5.1") || ua.Contains("Windows NT 5.2"))
        return "Windows XP";

    if (ua.Contains("Windows NT 6.0"))
        return "Windows Vista";

    if (ua.Contains("Windows NT 6.1"))
        return "Windows 7";

    if (ua.Contains("Windows NT 6.2"))
        return "Windows 8";

    if (ua.Contains("Windows NT 6.3"))
        return "Windows 8.1";

    if (ua.Contains("Windows NT 10"))
        return "Windows 10";

    //fallback to basic platform:
    return (ua.Contains("Mobile") ? " Mobile " : "");
}
public String GetMobileVersion(string userAgent, string device)
{
    var temp = userAgent.Substring(userAgent.IndexOf(device) + device.Length).TrimStart();
    var version = string.Empty;

    foreach (var character in temp)
    {
        var validCharacter = false;
        int test = 0;

        if (Int32.TryParse(character.ToString(), out test))
        {
            version += character;
            validCharacter = true;
        }

        if (character == '.' || character == '_')
        {
            version += '.';
            validCharacter = true;
        }

        if (validCharacter == false)
            break;
    }

    return version;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: static {} 
Csharp :: asp.net list find 
Csharp :: cache.TryGetValue in MemoryCache c# .net 
Csharp :: vb.net single quote in string 
Csharp :: windows form button image size 
Csharp :: getString 
Csharp :: Make a variable public without showing in the inspector 
Csharp :: windows forms tablelayoutpanel scroll 
Csharp :: how to set window position 
Csharp :: .net framework cheat sheet 
Csharp :: get image information using c# 
Csharp :: c# project 
Csharp :: c# string contain double quote 
Csharp :: var c# 
Csharp :: Create an array with random values c# 
Csharp :: convert array to list c# 
Csharp :: belgiumcampus 
Csharp :: c# declaration definition 
Csharp :: width="331" height="331" 
Csharp :: c# .net stringify data query 
Html :: favicon meta 
Html :: removing filepath from url using htaccess 
Html :: only accept image file input 
Html :: how to remove suggestions from input field 
Html :: bootstrap 5 carousel disable autoplay 
Html :: make element disappear on smaller screens in bootstrap 
Html :: how to install jquery 
Html :: html favicon.ico 
Html :: youtube video image 
Html :: a tag open in new tabn 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =