Inquiridor
Detectar dispositivo

Pergunta
-
Todas as Respostas
-
Use o Header "User-Agent" transmitido pelo navegador. Aqui há uma lista (bem grande) deles.
Para identificar dispositivos móveis, essa dica talvez seja válida:
http://www.developershome.com/wap/detection/detection.asp?page=userAgentHeader
To Determine Whether a User Agent is a Web Browser on a Personal Computer or a Microbrowser on a Mobile Device with the User-Agent Header
Another common use of the User-Agent header is to determine whether the user agent is a web browser on a personal computer or a microbrowser on a mobile device. Below shows the User-Agent header of Microsoft Internet Explorer 6 and Mozilla Firefox 1.0.7 running on Windows 2000:
Microsoft Internet Explorer 6:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Mozilla Firefox 1.0.7:
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7
If you compare the User-Agent headers of IE and Firefox with those of microbrowsers that were shown earlier, you will find that the User-Agent header of IE and Firefox contains the word "Mozilla" while those of microbrowsers do not. This can be served as a simple rule to determine whether a user agent is a web browser on a personal computer or a microbrowser on a mobile device.
Note that the above rule does not work in all cases. The User-Agent header of some microbrowsers also contains the word "Mozilla". For example, some Nokia 6630 cell phones use a "Mozilla compatible" User-Agent header. The reason is that Nokia 6630 is a web-compatible cell phone and can accept HTML content, but some websites that are designed for desktops will deny access to Nokia 6630 if the "Mozilla compatible" User-Agent header is not present.
"Mozilla compatible" User-Agent header of the Nokia 6630 cell phone:
Mozilla/4.0 (compatible; MSIE 5.0; Series60/2.8 Nokia6630/4.06.0 Profile/MIDP-2.0 Configuration/CLDC-1.1)
To increase accuracy, you can further check the OS name and browser name in the User-Agent header. For example, if you find the word "Mozilla" and the OS name "Windows NT" in the User-Agent string, it is almost certain that the user agent is a web browser on a computer but not on a mobile device; if you find the word "Mozilla" and the browser name "Firefox", it is certain that the user agent is a Firefox browser running on a computer since Firefox does not have a mobile device version (at the time of this writing).
Resumindo, você vai ter q definir alguns casos em que a sua págian deve mostrar (String nokia/samsung no user-agent, ou Windows, etc)
-
Mauricio,
Estava procurando a mesma solução e achei a seguinte em C#
public bool isMobileBrowser() { //GETS THE CURRENT USER CONTEXT HttpContext context = HttpContext.Current; //FIRST TRY BUILT IN ASP.NT CHECK if (context.Request.Browser.IsMobileDevice) { return true; } //THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null) { return true; } //THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP if (context.Request.ServerVariables["HTTP_ACCEPT"] != null && context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap")) { return true; } //AND FINALLY CHECK THE HTTP_USER_AGENT //HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null) { //Create a list of all mobile types string[] mobiles = new string[] { "midp", "j2me", "avant", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows ce", "mmp/", "blackberry", "mib/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up.b", "audio", "SIE-", "SEC-", "samsung", "HTC", "mot-", "mitsu", "sagem", "sony" , "alcatel", "lg", "eric", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "dddi", "moto", "iphone" }; //Loop through each item in the list created above //and check if the header contains that text foreach (string s in mobiles) { if (context.Request.ServerVariables["HTTP_USER_AGENT"].ToLower().Contains(s.ToLower())) { return true; } } } return false; }
Você conseguiu saber se o browser do dispositivo aceita html e/ou asp.net?
Abraço,
Clayr Madeira -
Veja o artigo Classe HttpBrowserCapabilities para Detectar Browser e Verificar Recursos do Navegador
Abraços, Marcelo Cavalini