服务器启动运行时间(单位:秒);服务器IP; 服务器域名;服务器操作系统;WEB服务器版本;.NET解释引擎版本;https支持情况;HTTP访问端口;服务器当前时间;虚拟目录绝对路径;虚拟目录绝对路径;虚拟目录Session总数;检查是否支持该组件..
服务器启动运行时间(单位:秒);服务器IP; 服务器域名;服务器操作系统;WEB服务器版本;.NET解释引擎版本;https支持情况;HTTP访问端口;服务器当前时间;虚拟目录绝对路径;虚拟目录绝对路径;虚拟目录Session总数;检查是否支持该组件等等信息:
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Web;
- using System.Runtime.InteropServices;
- /**//// <summary>
- /// 服务器相关信息
- /// </summary>
- public static class ServerInfo
- {
- private static CPU_INFO CpuInfo;
- private static MEMORY_INFO MemoryInfo;
- /**//// <summary>
- /// 静态构造函数
- /// </summary>
- static ServerInfo()
- {
- CpuInfo = new CPU_INFO();
- GetSystemInfo(ref CpuInfo);
- MemoryInfo = new MEMORY_INFO();
- GlobalMemoryStatus(ref MemoryInfo);
- }
- /**//// <summary>
- /// 服务器启动运行时间(单位:秒)
- /// </summary>
- public static string RunTime
- {
- get { return Convert.ToString(Environment.TickCount / 0x3e8); }
- }
- /**//// <summary>
- /// 服务器IP
- /// </summary>
- public static string IP
- {
- get { return HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"]; }
- }
- /**//// <summary>
- /// 服务器域名
- /// </summary>
- public static string DomainName
- {
- get { return HttpContext.Current.Request.ServerVariables["SERVER_NAME"]; }
- }
- /**//// <summary>
- /// 服务器操作系统
- /// </summary>
- public static string OS
- {
- get { return Environment.OSVersion.ToString(); }
- }
- /**//// <summary>
- /// WEB服务器版本
- /// </summary>
- public static string Soft
- {
- get { return HttpContext.Current.Request.ServerVariables["SERVER_SOFTWARE"]; }
- }
- /**//// <summary>
- /// .NET解释引擎版本
- /// </summary>
- public static string Net
- {
- get { return ".NET CLR " + Environment.Version.Major + "." + Environment.Version.Minor + "." + Environment.Version.Build + "." + Environment.Version.Revision; }
- }
- /**//// <summary>
- /// https支持情况
- /// </summary>
- public static string Https
- {
- get
- {
- return HttpContext.Current.Request.ServerVariables["HTTPS"];
- }
- }
- /**//// <summary>
- /// HTTP访问端口
- /// </summary>
- public static string Port
- {
- get { return HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; }
- }
- /**//// <summary>
- /// 服务器当前时间
- /// </summary>
- public static string Time
- {
- get { return DateTime.Now.ToString(); }
- }
- /**//// <summary>
- /// 虚拟目录绝对路径
- /// </summary>
- public static string PPatch
- {
- get { return HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"]; }
- }
- /**//// <summary>
- /// 虚拟目录绝对路径
- /// </summary>
- public static string NPatch
- {
- get { return HttpContext.Current.Request.ServerVariables["PATH_TRANSLATED"]; }
- }
- /**//// <summary>
- /// 虚拟目录Session总数
- /// </summary>
- public static string Session
- {
- get { return HttpContext.Current.Session.Count.ToString(); }
- }
- /**//// <summary>
- /// 虚拟目录Application总数
- /// </summary>
- public static string Application
- {
- get { return HttpContext.Current.Application.Count.ToString();}
- }
- /**//// <summary>
- /// 服务器计算机名
- /// </summary>
- public static string MachineName
- {
- get { return HttpContext.Current.Server.MachineName; }
- }
- /**//// <summary>
- /// 服务端脚本执行超时(单位:秒)
- /// </summary>
- public static string ScriptOut
- {
- get { return HttpContext.Current.Server.ScriptTimeout.ToString(); }
- }
- 服务器组件支持情况#region 服务器组件支持情况
- /**//// <summary>
- /// 检查是否支持该组件
- /// </summary>
- /// <param name="sObject">组件名,ProgId或ClassId。</param>
- /// <returns>是否支持该组件</returns>
- public static bool Check(string sObject)
- {
- try
- {
- //object chkObj = HttpContext.Current.Server.CreateObject(sObject);
- HttpContext.Current.Server.CreateObject(sObject);
- return true;
- }
- catch
- {
- return false;
- }
- }
- /**//// <summary>
- /// 是否支持Access
- /// </summary>
- public static bool Access
- {
- get { return Check("ADODB.RecordSet"); }
- }
- /**//// <summary>
- /// 是否支持FSO
- /// </summary>
- public static bool FSO
- {
- get { return Check("Scripting.FileSystemObject"); }
- }
- /**//// <summary>
- /// 是否支持CDONTS邮件发送
- /// </summary>
- public static bool CDONTSMail
- {
- get { return Check("CDONTS.NewMail"); }
- }
- /**//// <summary>
- /// 是否支持JMail邮件收发
- /// </summary>
- public static bool JMail
- {
- get { return Check("JMail.SmtpMail"); }
- }
- /**//// <summary>
- /// 是否支持ASPemail发信
- /// </summary>
- public static bool ASPemail
- {
- get { return Check("Persits.MailSender"); }
- }
- /**//// <summary>
- /// 是否支持Geocel发信
- /// </summary>
- public static bool Geoce
- {
- get { return Check("Geocel.Mailer"); }
- }
- /**//// <summary>
- /// 是否支持SmtpMail发信
- /// </summary>
- public static bool SmtpMail
- {
- get { return Check("SmtpMail.SmtpMail.1"); }
- }
- /**//// <summary>
- /// 是否支持ASPUpload文件上传
- /// </summary>
- public static bool ASPUpload
- {
- get { return Check("Persits.Upload.1"); }
- }
- /**//// <summary>
- /// 是否支持ASPCN文件上传
- /// </summary>
- public static bool ASPCNUpload
- {
- get { return Check("aspcn.Upload"); }
- }
- /**//// <summary>
- /// 是否支持SoftArtisans文件管理
- /// </summary>
- public static bool SoftArtisans
- {
- get { return Check("SoftArtisans.FileManager"); }
- }
- /**//// <summary>
- /// 是否支持Dimac文件上传
- /// </summary>
- public static bool DimacUpload
- {
- get { return Check("w3.upload"); }
- }
- /**//// <summary>
- /// 是否支持刘云峰文件上传组件
- /// </summary>
- public static bool LYFUpload
- {
- get { return Check("LyfUpload.UploadFile"); }
- }
- /**//// <summary>
- /// 是否支持Dimac的图像读写组件
- /// </summary>
- public static bool DimacImg
- {
- get { return Check("W3Image.Image"); }
- }
- }
using System;using System.Collections.Generic;using System.Text;using System.Web;using System.Runtime.InteropServices; /** <summary> /// 服务器相关信息 /// </summary> public static class ServerInfo { private static CPU_INFO CpuInfo; private static MEMORY_INFO MemoryInfo; /** <summary> /// 静态构造函数 /// </summary> static ServerInfo() { CpuInfo = new CPU_INFO(); GetSystemInfo(ref CpuInfo); MemoryInfo = new MEMORY_INFO(); GlobalMemoryStatus(ref MemoryInfo); } /** <summary> /// 服务器启动运行时间(单位:秒) /// </summary> public static string RunTime { get { return Convert.ToString(Environment.TickCount / 0x3e8); } } /** <summary> /// 服务器IP /// </summary> public static string IP { get { return HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"]; } } /** <summary> /// 服务器域名 /// </summary> public static string DomainName { get { return HttpContext.Current.Request.ServerVariables["SERVER_NAME"]; } } /** <summary> /// 服务器操作系统 /// </summary> public static string OS { get { return Environment.OSVersion.ToString(); } } /** <summary> /// WEB服务器版本 /// </summary> public static string Soft { get { return HttpContext.Current.Request.ServerVariables["SERVER_SOFTWARE"]; } } /** <summary> /// .NET解释引擎版本 /// </summary> public static string Net { get { return ".NET CLR " + Environment.Version.Major + "." + Environment.Version.Minor + "." + Environment.Version.Build + "." + Environment.Version.Revision; } } /** <summary> /// https支持情况 /// </summary> public static string Https { get { return HttpContext.Current.Request.ServerVariables["HTTPS"]; } } /** <summary> /// HTTP访问端口 /// </summary> public static string Port { get { return HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; } } /** <summary> /// 服务器当前时间 /// </summary> public static string Time { get { return DateTime.Now.ToString(); } } /** <summary> /// 虚拟目录绝对路径 /// </summary> public static string PPatch { get { return HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"]; } } /** <summary> /// 虚拟目录绝对路径 /// </summary> public static string NPatch { get { return HttpContext.Current.Request.ServerVariables["PATH_TRANSLATED"]; } } /** <summary> /// 虚拟目录Session总数 /// </summary> public static string Session { get { return HttpContext.Current.Session.Count.ToString(); } } /** <summary> /// 虚拟目录Application总数 /// </summary> public static string Application { get { return HttpContext.Current.Application.Count.ToString();} } /** <summary> /// 服务器计算机名 /// </summary> public static string MachineName { get { return HttpContext.Current.Server.MachineName; } } /** <summary> /// 服务端脚本执行超时(单位:秒) /// </summary> public static string ScriptOut { get { return HttpContext.Current.Server.ScriptTimeout.ToString(); } } 服务器组件支持情况#region 服务器组件支持情况 /** <summary> /// 检查是否支持该组件 /// </summary> /// <param name="sObject">组件名,ProgId或ClassId。</param> /// <returns>是否支持该组件</returns> public static bool Check(string sObject) { try { //object chkObj = HttpContext.Current.Server.CreateObject(sObject); HttpContext.Current.Server.CreateObject(sObject); return true; } catch { return false; } } /** <summary> /// 是否支持Access /// </summary> public static bool Access { get { return Check("ADODB.RecordSet"); } } /** <summary> /// 是否支持FSO /// </summary> public static bool FSO { get { return Check("Scripting.FileSystemObject"); } } /** <summary> /// 是否支持CDONTS邮件发送 /// </summary> public static bool CDONTSMail { get { return Check("CDONTS.NewMail"); } } /** <summary> /// 是否支持JMail邮件收发 /// </summary> public static bool JMail { get { return Check("JMail.SmtpMail"); } } /** <summary> /// 是否支持ASPemail发信 /// </summary> public static bool ASPemail { get { return Check("Persits.MailSender"); } } /** <summary> /// 是否支持Geocel发信 /// </summary> public static bool Geoce { get { return Check("Geocel.Mailer"); } } /** <summary> /// 是否支持SmtpMail发信 /// </summary> public static bool SmtpMail { get { return Check("SmtpMail.SmtpMail.1"); } } /** <summary> /// 是否支持ASPUpload文件上传 /// </summary> public static bool ASPUpload { get { return Check("Persits.Upload.1"); } } /** <summary> /// 是否支持ASPCN文件上传 /// </summary> public static bool ASPCNUpload { get { return Check("aspcn.Upload"); } } /** <summary> /// 是否支持SoftArtisans文件管理 /// </summary> public static bool SoftArtisans { get { return Check("SoftArtisans.FileManager"); } } /** <summary> /// 是否支持Dimac文件上传 /// </summary> public static bool DimacUpload { get { return Check("w3.upload"); } } /** <summary> /// 是否支持刘云峰文件上传组件 /// </summary> public static bool LYFUpload { get { return Check("LyfUpload.UploadFile"); } } /** <summary> /// 是否支持Dimac的图像读写组件 /// </summary> public static bool DimacImg { get { return Check("W3Image.Image"); } } }