ASP.NET获取客户端操作系统类型和IP地址

简介:
+关注继续查看

1:

protected void Page_Load(object sender, EventArgs e)
ExpandedBlockStart.gif {
this.lblIP.Text = Request.UserHostAddress.ToString();//获取IP

string strSysVersion = "其他";
string strAgentInfo = Request.ServerVariables["HTTP_USER_AGENT"];

if (strAgentInfo.Contains("NT 5.2"))
ExpandedSubBlockStart.gif{
strSysVersion = "Windows 2003";
}

else if (strAgentInfo.Contains("NT 5.1"))
ExpandedSubBlockStart.gif{
strSysVersion = "Windows XP";
}

else if (strAgentInfo.Contains("NT 5"))
ExpandedSubBlockStart.gif{
strSysVersion = "Windows 2000";
}

else if (strAgentInfo.Contains("NT 4.9"))
ExpandedSubBlockStart.gif{
strSysVersion = "Windows ME";
}

else if (strAgentInfo.Contains("NT 4"))
ExpandedSubBlockStart.gif{
strSysVersion = "Windows NT4";
}

else if (strAgentInfo.Contains("NT 98"))
ExpandedSubBlockStart.gif{
strSysVersion = "Windows 98";
}

else if (strAgentInfo.Contains("NT 95"))
ExpandedSubBlockStart.gif{
strSysVersion = "Windows 95";
}

else if (strSysVersion.ToLower().Contains("Mac"))
ExpandedSubBlockStart.gif{
strSysVersion = "Mac";
}

else if (strSysVersion.ToLower().Contains("unix"))
ExpandedSubBlockStart.gif{
strSysVersion = "UNIX";
}

else if (strSysVersion.ToLower().Contains("linux"))
ExpandedSubBlockStart.gif{
strSysVersion = "Linux";
}

else if (strSysVersion.Contains("SunOS"))
ExpandedSubBlockStart.gif{
strSysVersion = "SunOS";
}

this.lblOpSys.Text = strSysVersion;
}

2:

private string getIp()
2 { /*穿过代理服务器取远程用户真实IP地址:*/
3 if(Request.ServerVariables["HTTP_VIA"]!=null)
4 return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
5 else
6 return Request.ServerVariables["REMOTE_ADDR"].ToString();
7 }

8Label2.Text =getIp();
9HttpBrowserCapabilities bc = new HttpBrowserCapabilities();
10bc = Request.Browser;
11string xitong ="你的操作系统为";
12Label3.Text=xitong+bc.Platform + " 浏览器类型:" + bc.Type;




本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2010/01/05/1639900.html,如需转载请自行联系原作者

相关文章
|
2月前
|
开发框架 前端开发 JavaScript
ASP.NET Core MVC 从入门到精通之wwwroot和客户端库
ASP.NET Core MVC 从入门到精通之wwwroot和客户端库
51 0
|
.NET
在ASP.NET Core 2.x中获取客户端IP地址
一、前言 大家也知道服务端请求时我们获取的IP地址是包含在请求头中,因此这也大大便利了IP的获取。 在ASP.NET中,可以通过以下方式获取客户端的IP地址。 HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] 但这不适用于ASP.NET Core 2.0。
1826 0
|
Web App开发 .NET CDN
再论 ASP.NET 中获取客户端IP地址
原文:再论 ASP.NET 中获取客户端IP地址 说到IP获取无非是我们常见的以下几种方式,但是具体获取的值具体区别在哪?网上不乏相关文章,说的也是很详细,但是真正使用起来,还有很多不太对的地方。IP在不同系统中,应用相当广泛,常见的日志记录、广告分区域投放等。
1256 0
相关产品
云迁移中心
推荐文章
更多