asp.net获取客户端参数与操作系统信息

发布时间:2020-02-24编辑:脚本学堂
分享一个asp.net获取客户端参数或操作系统信息的例子,有关asp.net获取客户端参数的方法,有需要的朋友参考下。

例子,asp.net获取客户端参数与操作系统信息的实现代码。

代码:
 

复制代码 代码示例:

/// <summary>
/// 获取用户操作系统信息
/// </summary>
/// <returns></returns>
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.jb200.com 编辑整理)

/// <summary>
/// 获取客户端浏览器类型及版本
/// </summary>
/// <returns></returns>
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()
/// <summary>
/// 获取IP
/// </summary>
/// <returns></returns>
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