2010-09-08 25 views
24

那裏是否存在.NET庫,它將解釋存儲的用戶代理字符串,併爲您提供一個包含所包含信息的強類型對象?用於解釋用戶代理字符串的.NET庫

+0

http://www.hanselman.com/blog/TheNETFrameworkAndTheBrowsersUserAgentString.aspx – pm100 2010-10-01 16:26:48

+0

檢查此鏈接 - 希望這可以幫助你 - http://blogs.msdn.com/b/ie/archive/2005/04/27/ 412813.aspx – 2010-09-08 09:43:33

+3

選中此鏈接:[http://user-agent-string.info/download/UASparser-for-dotNET](http://user-agent-string.info/download/UASparser-for-dotNET) – 2010-10-15 09:07:39

回答

5

如果您需要用戶代理字符串,則可以使用HttpRequest.Browser屬性。 嘗試使用瀏覽器功能而不是瀏覽器版本來編程您的網站。

http://msdn.microsoft.com/en-us/library/system.web.httprequest.browser.aspx

HttpBrowserCapabilities bc = Request.Browser; 
Response.Write("<p>Browser Capabilities:</p>"); 
Response.Write("Type = " + bc.Type + "<br>"); 
Response.Write("Name = " + bc.Browser + "<br>"); 
Response.Write("Version = " + bc.Version + "<br>"); 
Response.Write("Major Version = " + bc.MajorVersion + "<br>"); 
Response.Write("Minor Version = " + bc.MinorVersion + "<br>"); 
Response.Write("Platform = " + bc.Platform + "<br>"); 
Response.Write("Is Beta = " + bc.Beta + "<br>"); 
Response.Write("Is Crawler = " + bc.Crawler + "<br>"); 
Response.Write("Is AOL = " + bc.AOL + "<br>"); 
Response.Write("Is Win16 = " + bc.Win16 + "<br>"); 
Response.Write("Is Win32 = " + bc.Win32 + "<br>"); 
Response.Write("Supports Frames = " + bc.Frames + "<br>"); 
Response.Write("Supports Tables = " + bc.Tables + "<br>"); 
Response.Write("Supports Cookies = " + bc.Cookies + "<br>"); 
Response.Write("Supports VB Script = " + bc.VBScript + "<br>"); 
Response.Write("Supports JavaScript = " + bc.JavaScript + "<br>"); 
Response.Write("Supports Java Applets = " + bc.JavaApplets + "<br>"); 
Response.Write("Supports ActiveX Controls = " + bc.ActiveXControls + "<br>"); 
Response.Write("CDF = " + bc.CDF + "<br>"); 
+0

我正在從用戶代理字符串的日誌工作。有什麼方法可以在http請求之後使用HttpBrowserCapabilities來解析用戶代理字符串(long)嗎? – 2010-09-08 09:55:05

+0

也許你可以創建一個httprequest,然後設置代理字符串中的頭文件,它會以這種方式工作,沒有測試過。 – Stefan 2010-09-08 09:57:21

14
 var browserCapabilities = new HttpBrowserCapabilities 
     { 
      Capabilities = new Hashtable { { string.Empty, userAgent } } 
     }; 

     var capabilitiesFactory = new BrowserCapabilitiesFactory(); 

     capabilitiesFactory.ConfigureBrowserCapabilities(new NameValueCollection(), browserCapabilities); 

     return browserCapabilities; 
11

你可以試試這個ua-parser它似乎是相當頻繁更新!