ASP.net中获取客户端参数操作系统信息
程序员文章站
2024-02-26 16:40:10
复制代码 代码如下: /// /// 获取用户操作系统信息 /// /// ...
复制代码 代码如下:
/// <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;
}
/// <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
上一篇: 浅谈function(函数)中的动态参数