asp.net获取客户端参数与操作系统信息
本文导语: 例子,asp.net获取客户端参数与操作系统信息的实现代码。 代码: 代码示例: /// /// 获取用户操作系统信息 /// /// public string getuseros() { string strsysversion = "其他"; httprequest request = httpcontext.current.request; string stragen...
例子,asp.net获取客户端参数与操作系统信息的实现代码。
代码:
///
/// 获取用户操作系统信息
///
///
public string getuseros()
{
string strsysversion = "其他";
httprequest request = httpcontext.current.request;
string stragentinfo = request.servervariables["http_user_agent"];
if (stragentinfo.contains("nt 6.0"))
{
strsysversion = "windows vista";
}
else if (stragentinfo.contains("nt 5.2"))
{
strsysversion = "windows 2003";
}
else if (stragentinfo.contains("nt 5.1"))
{
strsysversion = "windows xp";
}
else if (stragentinfo.contains("nt 5"))
{
strsysversion = "windows 2000";
}
else if (stragentinfo.contains("nt 4.9"))
{
strsysversion = "windows me";
}
else if (stragentinfo.contains("nt 4"))
{
strsysversion = "windows nt4";
}
else if (stragentinfo.contains("nt 98"))
{
strsysversion = "windows 98";
}
else if (stragentinfo.contains("nt 95"))
{
strsysversion = "windows 95";
}
else if (strsysversion.tolower().contains("mac"))
{
strsysversion = "mac";
}
else if (strsysversion.tolower().contains("unix"))
{
strsysversion = "unix";
}
else if (strsysversion.tolower().contains("linux"))
{
strsysversion = "linux";
}
else if (strsysversion.contains("sunos"))
{
strsysversion = "sunos";
}
return strsysversion;
} //(脚本学堂 www. 编辑整理)
///
/// 获取客户端浏览器类型及版本
///
///
public string getuserbrowser()
{
string strbrowser = "其他";
httprequest request = httpcontext.current.request;
string stragentinfo = request.servervariables["http_user_agent"];
if (regex.ismatch(stragentinfo, "msie ([//d]//.[//d])", regexoptions.ignorecase | regexoptions.compiled))
{
strbrowser = regex.match(stragentinfo, "msie ([//d]//.[//d])").result("ie:$1");
}
else if (regex.ismatch(stragentinfo, "opera ([//d]//.[//d])", regexoptions.ignorecase | regexoptions.compiled))
{
strbrowser = regex.match(stragentinfo, "opera ([//d]//.[//d])").result("opera:$1");
}
else if (regex.ismatch(stragentinfo, "opera///([//d]//.[//d])", regexoptions.ignorecase | regexoptions.compiled))
{
strbrowser = regex.match(stragentinfo, "opera///([//d]//.[//d])").result("opera:$1");
}
else if (regex.ismatch(stragentinfo, "firefox///([//d]//.[//d])", regexoptions.ignorecase | regexoptions.compiled))
{
strbrowser = regex.match(stragentinfo, "firefox///([//d]//.[//d])").result("firefox:$1");
}
return strbrowser;
}
#region getip()
///
/// 获取IP
///
///
public string getip()
{
string uip = "";
if (httpcontext.current.request.servervariables["http_via"] != null)
{
uip = httpcontext.current.request.servervariables["http_x_forwarded_for"].tostring();
}
else
{
uip = httpcontext.current.request.servervariables["remote_addr"].tostring();
}
return uip;
}
#endregion