用于解释用户代理字符串的.NET lib

时间:2010-09-08 09:35:05

标签: c# .net user-agent

是否存在.NET库,它将解释存储的用户代理字符串并为您提供包含信息的强类型对象?

3 个答案:

答案 0 :(得分:16)

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

        var capabilitiesFactory = new BrowserCapabilitiesFactory();

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

        return browserCapabilities;

答案 1 :(得分:12)

你可以尝试这个ua-parser它似乎经常更新!

编辑:现在看来ua-parser或多或少死了,DeviceDetector.NET似乎正在积极开发中。

答案 2 :(得分: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>");