CPU个数: @Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")
CPU类型: @Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")
CPU频率: @ViewBag.CPUGHZ
服务器内存大小: @ViewBag.TotalMemory
服务器磁盘大小: @ViewBag.TotalDisk
虚拟目录绝对路径: @Request.ServerVariables["APPL_PHYSICAL_PATH"]
执行文件绝对路径: @Request.ServerVariables["PATH_TRANSLATED"]
虚拟目录Session总数: @Session.Contents.Count
////// 获取CPU频率 /// ///public string GetCpuGHZ() { ManagementClass mc = new ManagementClass("Win32_Processor"); ManagementObjectCollection cpus = mc.GetInstances(); string str = ""; string[] mHz = new string[cpus.Count]; int c = 0; ManagementObjectSearcher mySearch = new ManagementObjectSearcher("select * from Win32_Processor"); foreach (ManagementObject mo in mySearch.Get()) { double temp = Convert.ToInt64(mo.Properties["CurrentClockSpeed"].Value); mHz[c] = temp.ToString(); str += (temp/1000).ToString("0.00") + "GHz,"; c++; } mc.Dispose(); mySearch.Dispose(); // return mHz; return str.TrimEnd(','); } /// /// 获取内存大小 /// ///public string GetTotalPhysicalMemory() { try { string st = " "; ManagementClass mc = new ManagementClass("Win32_ComputerSystem"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { st = mo["TotalPhysicalMemory"].ToString(); } moc = null; mc = null; return st; } catch { return "0"; } finally { } } /// /// 硬盘大小 /// ///public string GetSizeOfDisk() { ManagementClass mc = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moj = mc.GetInstances(); foreach (ManagementObject m in moj) { return m.Properties["Size"].Value.ToString(); } return "0"; }
比较全的获取服务器信息:
https://www.cnblogs.com/tylerdonet/archive/2013/04/07/3006278.html
比较全的Request 用法:
https://www.cnblogs.com/mazhenyu/p/9468441.html