0
我創建了一個代碼,用於檢查瀏覽器是否只能在Google Chrome上訪問並限制Mozilla Firefox。例如,我使用的只是使用谷歌瀏覽器的Android手機,如果iPhone或iPad Google Chrome瀏覽器有權訪問該網站。但是,當檢查瀏覽器是Chrome還是Mozilla時,它會被視爲Safari。使用C#,工具。所以我調查它是否有一個獨特的財產,很好用,但可悲的是沒有。有沒有一個好的插件或庫或框架來檢測iPhone或Android瀏覽器。謝謝。爲什麼iPhone將Google Chrome視爲Safari還將Mozilla Firefox視爲Safari瀏覽器?
這是用於谷歌瀏覽器。
var userAgent = filterContext.HttpContext.Request.UserAgent?.ToLowerInvariant() ?? "";
"mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko) version/9.0 mobile/13b143 safari/601.1"
var userBrowser = filterContext.HttpContext.Request.Browser.Browser?.ToLowerInvariant() ?? "";
"safari"
var userBrowserTypeype = filterContext.HttpContext.Request.Browser.Type;
"Safari9"
var userBrowserVersion = filterContext.HttpContext.Request.Browser.Version;
"9.0"
var userBrowserMajorVersion = filterContext.HttpContext.Request.Browser.MajorVersion;
"9"
var userBrowserMinorVersion = filterContext.HttpContext.Request.Browser.MinorVersion;
0
var userBrowserPlatform = filterContext.HttpContext.Request.Browser.Platform;
"Unknown"
var userBrowserBeta = filterContext.HttpContext.Request.Browser.Beta;
false
var userBrowserCrawler = filterContext.HttpContext.Request.Browser.Crawler;
false
var userAol = filterContext.HttpContext.Request.Browser.AOL;
false
var userBrowserWin16 = filterContext.HttpContext.Request.Browser.Win16;
false
var userBrowserWin32 = filterContext.HttpContext.Request.Browser.Win32;
false
var userBrowserFrames = filterContext.HttpContext.Request.Browser.Frames;
true
var usBrowserTables = filterContext.HttpContext.Request.Browser.Tables;
true
var userBrowserCookies = filterContext.HttpContext.Request.Browser.Cookies;
true
var userBrowserVbScript = filterContext.HttpContext.Request.Browser.VBScript;
false
這是用於Mozilla Firefox的。
var userAgent = filterContext.HttpContext.Request.UserAgent?.ToLowerInvariant() ?? "";
"mozilla/5.0 (iphone; cpu iphone os 10_2_1 like mac os x) applewebkit/602.4.6 (khtml, like gecko) version/10.0 mobile/14d27 safari/602.1"
var userBrowser = filterContext.HttpContext.Request.Browser.Browser?.ToLowerInvariant() ?? "";
"safari"
var userBrowserTypeype = filterContext.HttpContext.Request.Browser.Type;
"Safari10"
var userBrowserVersion = filterContext.HttpContext.Request.Browser.Version;
"10.0"
var userBrowserMajorVersion = filterContext.HttpContext.Request.Browser.MajorVersion;
"10"
var userBrowserMinorVersion = filterContext.HttpContext.Request.Browser.MinorVersion;
0
var userBrowserPlatform = filterContext.HttpContext.Request.Browser.Platform;
"Unknown"
var userBrowserBeta = filterContext.HttpContext.Request.Browser.Beta;
false
var userBrowserCrawler = filterContext.HttpContext.Request.Browser.Crawler;
false
var userAol = filterContext.HttpContext.Request.Browser.AOL;
false
var userBrowserWin16 = filterContext.HttpContext.Request.Browser.Win16;
false
var userBrowserWin32 = filterContext.HttpContext.Request.Browser.Win32;
false
var userBrowserFrames = filterContext.HttpContext.Request.Browser.Frames;
true
var usBrowserTables = filterContext.HttpContext.Request.Browser.Tables;
true
var userBrowserCookies = filterContext.HttpContext.Request.Browser.Cookies;
true
var userBrowserVbScript = filterContext.HttpContext.Request.Browser.VBScript;
false
謝謝你,朋友,現在我放心了。最後。 – Chuck
是否有另一種方法來檢查瀏覽器組件和用戶代理? – Chuck
不幸的是,沒有真正確定的方式來做到這一點,但在[這個線程]中接受的答案(https://stackoverflow.com/questions/7702325/the-best-way-to-detect-browser-in-js)從不同的角度解決問題可能有所幫助。 – einord