asp.Netはサーバ情報を取得する:IISバージョン/.Netバージョン

4251 ワード

/**
 *zfy 2014-11-29
 *        
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Mvc.Util
{
    class Server
    {
        /// <summary>
        ///        
        /// </summary>
        /// <returns></returns>
        public static string GetSystemVersion()
        {
            return Environment.OSVersion.ToString();
        }

        /// <summary>
        ///         
        /// </summary>
        /// <returns></returns>
        public static string GetServerName()
        {
            return HttpContext.Current.Server.MachineName;//     
        }

        /// <summary>
        ///    IP    
        /// </summary>
        /// <returns></returns>
        public static string GetServerIp()
        {
            return HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];
        }

        /// <summary>
        ///        
        /// </summary>
        /// <returns></returns>
        public static string GetDomainName()
        {
            return HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
        }

        /// <summary>
        /// /.NET      
        /// </summary>
        /// <returns></returns>
        public static string GetDotNetVersion()
        {
            return ".NET CLR" + Environment.Version.Major + "." + Environment.Version.Minor + "." + Environment.Version.Build + "." + Environment.Version.Revision;
        }

        /// <summary>
        /// IIS  
        /// </summary>
        /// <returns></returns>
        public static string GetServerSoftware()
        {
            return HttpContext.Current.Request.ServerVariables["SERVER_SOFTWARE"];
        }

        /// <summary>
        /// HTTP      
        /// </summary>
        /// <returns></returns>
        public static string GetServerPort()
        {
            return HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
        }

        /// <summary>
        ///            
        /// </summary>
        /// <returns></returns>
        public static string GetApplRhysicalPath()
        {
            return HttpContext.Current.Request.ServerVariables["APPL_RHYSICAL_PATH"];
        }

        /// <summary>
        ///            
        /// </summary>
        /// <returns></returns>
        public static string GetPathTranslated()
        {
            return HttpContext.Current.Request.ServerVariables["PATH_TRANSLATED"];
        }

        /// <summary>
        ///     Session   
        /// </summary>
        /// <returns></returns>
        public static string GetSessionCount()
        {
            return HttpContext.Current.Session.Contents.Count.ToString();
        }

        /// <summary>
        ///     Application    
        /// </summary>
        /// <returns></returns>
        public static string GetApplicationCount()
        {
            return HttpContext.Current.Application.Contents.Count.ToString();
        }

        /// <summary>
        ///         
        /// </summary>
        /// <returns></returns>
        public static string GetAcceptLanguage()
        {
            return HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];//         
        }

        /// <summary>
        /// CPU      
        /// </summary>
        /// <returns></returns>
        public static string GetCpuCount()
        {
            return Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");//CPU      
        }

        /// <summary>
        /// CPU   
        /// </summary>
        /// <returns></returns>
        public static string GetCpuIdentifier()
        {
            return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER");//CPU      
        }

    }
}