Last active
December 16, 2015 11:38
-
-
Save luisrudge/5428614 to your computer and use it in GitHub Desktop.
Some thoughts around server side browser detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BrowserInfo | |
{ | |
private readonly HttpContextBase _context; | |
public BrowserInfo(HttpContextBase context) | |
{ | |
_context = context; | |
} | |
public HttpBrowserCapabilitiesBase HttpBrowserCapabilities | |
{ | |
get { return _context.Request.Browser; } | |
} | |
public string UserAgent { get { if (_context.Request == null) return ""; return _context.Request.UserAgent ?? ""; } } | |
public bool IsUnknown { get { return !IsFirefox && !IsGoogleChrome && !IsOpera && !IsInternetExplorer; } } | |
public bool IsInternetExplorer { get { return UserAgent.Contains("MSIE"); } } | |
public bool IsGoogleChrome { get { return UserAgent.Contains("Chrome"); } } | |
public bool IsFirefox { get { return UserAgent.Contains("Firefox"); } } | |
public bool IsOpera { get { return UserAgent.Contains("Opera"); } } | |
public bool IsSafari { get { return UserAgent.Contains("Opera"); } } | |
public bool IsMobile { get { return UserAgent.Contains("Mobile") || UserAgent.Contains("Android"); } } | |
public int MajorVersion { get { return HttpBrowserCapabilities.MajorVersion; } } | |
public string Version { get { return HttpBrowserCapabilities.Version; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment