您的位置:首页 > 编程语言 > C#

C#服务器端获取用户设备信息

2018-04-01 19:33 661 查看
C#服务器使用Request.UserAgent

使用语言:C#

环境:.net Framework 4.6.1 (当前使用) MVC4 (貌似支持所有NetWeb环境,我就不多说了)

using System;
using System.Web.Mvc;

namespace ServerMonitoring.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
String userAgent;
userAgent = Request.UserAgent;
bool
_windows = userAgent.Contains("Windows NT"),

4000
_mac = userAgent.Contains("Macintosh"),
_iphone = userAgent.Contains("iPhone"),
_android = userAgent.Contains("Android")
;
if (_windows)
{
Response.Write("您的平台可能是win!微软系统:windows");
}
else if (_mac)
{
Response.Write("您的平台可能是Mac!苹果系统:Mac");
}
else if (_iphone)
{
Response.Write("您的平台可能是Iphone!苹果系统:Ios");
}
else if (_android)
{
Response.Write("您的平台可能是Android!安卓系统:Android");
}
else
{
Response.Write("未能识别您的系统");
}
return View();
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息