where can i get Request.Browser.Platform items from?
i want to have pre-made list of most common OSes in my DB and all non default to be listed as other. Problem is i don't know what OSes called in Request.Browser object.
List i want to have WinXP, Vista, Win7, Linux, MacOS and other...
Do any of you know what are exact names of these OSes in Re开发者_StackOverflow中文版quest.Browser.Platform or where i can get list of values from ?
It's actually part of the user-agent string:
http://en.wikipedia.org/wiki/User_agent
Answering my own, maybe i my question was wrong. I wanted list of default OSes returned either from Request.Browser.Platform or Request["HTTP_USER_AGENT"] so i can enter those into DB.
I've got the list and wrote a function to check what kind of OS user uses.
public static string getOsFromUserAgent(string userAgent)
{
string visitorOS = "other";
Dictionary<string, string> osNamesAndRegexes = new Dictionary<string, string>();
osNamesAndRegexes.Add("Windows 98", "(Windows 98)|(Win98)");
osNamesAndRegexes.Add("Windows XP", "(Windows NT 5.1)|(Windows XP)");
osNamesAndRegexes.Add("Windows Vista", "(Windows NT 6.0)");
osNamesAndRegexes.Add("Windows 7", "(Windows NT 7.0)");
osNamesAndRegexes.Add("Linux", "(Linux)|(X11)");
osNamesAndRegexes.Add("Mac OS", "(Mac_PowerPC)|(Macintosh)");
foreach (KeyValuePair<string, string> kvpPair in osNamesAndRegexes)
{
if (Regex.IsMatch(userAgent, kvpPair.Value, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
visitorOS = kvpPair.Key;
}
}
return visitorOS;
}
精彩评论