0
A
回答
0
如果您只想知道布爾值值,則可以使用以下幫助程序方法。
如果您想了解有關所需設備的更多詳細信息,您需要使用第三方庫,如。
public static bool IsMobileBrowser(HttpContext context)
{
// first try built in asp.net 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;
}
// Finally check the http_user_agent header variable for any one of the following
if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
{
// List of all mobile types
string[] mobiles =
new[]
{
"android", "opera mini", "midp", "j2me", "avant", "docomo", "novarra", "palmos", "palmsource",
"240×320", "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", "dddi", "moto", "iphone"
};
// Check if the header contains that text
var userAgent = context.Request.ServerVariables["HTTP_USER_AGENT"].ToLower();
return mobiles.Any(userAgent.Contains);
}
return false;
}
相關問題
- 1. 回去或重定向到url
- 2. 重定向流量
- 3. 這些流重定向如何工作?
- 4. 如何去除pmpro重定向到水平頁面
- 5. 如何回重定向到
- 6. 如何重定向到PartialViewResult
- 7. 如何重定向到about.jsp?
- 8. Sharepoint工作流程 - 條件重定向
- 9. PHP - 完成流程後重定向PHP
- 10. HRD別名將流量重定向到?
- 11. 將流量重定向到CDN
- 12. C#Facebook SDK授權流程 - 如何重定向回頁面?
- 13. 如何將傳出流量重定向到另一個地址?
- 14. 如何使用.htaccess文件將HTTP流量重定向到HTTPS
- 15. 如何僅在訪客首次到達時重定向流量?
- 16. NativeScript如何將相機流重定向到HTML Canvas?
- 17. html:如何將流量重定向到不同的網址?
- 18. 如何將Facebook流量重定向到另一個網站
- 19. C#如何將流重定向到控制檯Out?
- 20. 如何將所有http流量重定向到https
- 21. 重定向所有流量
- 22. DOMPDF - 流後重定向PDF
- 23. 重定向標準流
- 24. 如何重定向和重定向
- 25. Visual Basic(Visual Studio 2005)將輸入流重定向到進程
- 26. IDP和SP身份驗證流程無需重定向到IDP
- 27. 如何根據第一塊中的數據將流重定向到其他流?
- 28. 如何更改303重定向到301在PHP中重定向
- 29. 如何通過Codeigniter中的重定向URL重定向到URL?
- 30. 如何使用重寫過程重定向到當前目錄
我不知道「重定向到流程去」是什麼意思。你能澄清一下嗎?爲什麼不建立一個響應式網站而不是在其他地方發送移動用戶呢?這與桌面應用程序標籤有什麼關係? – mason