我如何从Request.UserAgent得到公正的操作系统? [英] How do I get just the OS from Request.UserAgent?

查看:165
本文介绍了我如何从Request.UserAgent得到公正的操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我正在一个ASP.Net网站(C#$ C $后面c)如要解决疑难问题的原因(我们的大多数客户调用的技术支持不知道他们是什么操作系统/浏览器/ BrowserVersion的使用),我们要记录一个系统配置可以这么说,让我们可以更容易地解决操作系统/浏览器相关的问题。

目前,我使用 Request.UserAgent 。这里的问题是,它返回一个字符串,它无助于我们的支持人员:


  

    

的Mozilla / 5.0(Windows NT的6.1; RV:24.0)的Gecko / 20100101火狐/ 24.0


  

我想要做的是自己拉刚操作系统(Windows NT的6.1,或任何操作系统的用户),无需额外的浏览器信息,因为我已经分离等系统信息,例如:


  

    

|用户名| UserOS | BrowserType | BrowserName | MajorVersion | MinorVersion | IsBeta |


    
    

| 11111 | userOS * | * Firefox24.0 * | * *火狐* * | * * * * * 24 * * * * | * * * * 0 * * * * | * 0 * * |


  

是否有可能只是为了自身获得OS?

奖励积分,如果你知道如何从客户机(即Windows 7的VS的Windows NT 6.1)获得OS友好名称,这会救我脱离不必创建OS号码单独的数据库。


解决方案

用户代理是不会给你一个友好的名称,以便您将需要保持一个列表,沿着这个线的东西应该工作...

 词典<字符串,字符串> osList =新词典<字符串,字符串>
        {
            {的Windows NT 6.3,Windows 8.1中},
            {的Windows NT 6.2,Windows 8的},
            {的Windows NT 6.1,Windows 7的},
            {的Windows NT 6.0,Windows Vista中},
            {的Windows NT 5.2,Windows Server 2003的},
            {的Windows NT 5.1,Windows XP中},
            {的Windows NT 5.0,Windows 2000的}
        };        字符串userAgentText = HttpContext.Current.Request.UserAgent;        如果(userAgentText!= NULL)
        {
            INT的startPoint = userAgentText.IndexOf('(')+ 1;
            INT终点= userAgentText.IndexOf(';');            字符串OSVERSION = userAgentText.Substring(的startPoint,(端点 - 的startPoint));
            字符串friendlyOsName = osList [OSVERSION]
        }

Okay, so I am working on an ASP.Net website (C# code behind) where, for troubleshooting reasons (most of our clients that call for tech support don't know what OS/Browser/BrowserVersion they are using), we want to log a "system profile" so to speak so that we can more easily troubleshoot OS/Browser related issues.

Currently, I am using Request.UserAgent. The problem with this is that it returns a string that is unhelpful to our support staff:

Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0

What I want to do is to pull just the OS (Windows NT 6.1, or whatever OS the user has) by itself, without the additional browser information, as I am already segregating other system information as such:

| UserID | UserOS | BrowserType | BrowserName | MajorVersion | MinorVersion | IsBeta |

| 11111 | userOS* | * Firefox24.0 * | * * Firefox * * |* * * * * 24 * * * * |* * * * 0 * * * * | * * 0 * *|

Is it possible just to get the OS by itself?

Bonus points if you know how to get the OS Friendly name from a client machine (i.e. Windows 7 vs Windows NT 6.1), this would save me from having to create a separate database of OS numbers.

解决方案

The User Agent is not going to give you a friendly name so you will need to maintain a list, something along the lines of this should work...

        Dictionary<string, string> osList = new Dictionary<string, string>
        {
            {"Windows NT 6.3", "Windows 8.1"},
            {"Windows NT 6.2", "Windows 8"},
            {"Windows NT 6.1", "Windows 7"},
            {"Windows NT 6.0", "Windows Vista"},
            {"Windows NT 5.2", "Windows Server 2003"},
            {"Windows NT 5.1", "Windows XP"},
            {"Windows NT 5.0", "Windows 2000"}
        };

        string userAgentText = HttpContext.Current.Request.UserAgent;

        if (userAgentText != null)
        {
            int startPoint = userAgentText.IndexOf('(') + 1;
            int endPoint = userAgentText.IndexOf(';');

            string osVersion = userAgentText.Substring(startPoint, (endPoint - startPoint));
            string friendlyOsName = osList[osVersion];
        }

这篇关于我如何从Request.UserAgent得到公正的操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆