ASP.Net 獲取伺服器資訊

Web開發者發表於2012-02-04
            Response.Write("伺服器機器名:" + Server.MachineName); 
            Response.Write("<br/>");
            Response.Write("伺服器IP地址:" + Request.ServerVariables["LOCAL_ADDR"]);
            Response.Write("<br/>");
            Response.Write("伺服器域名:" + Request.ServerVariables["SERVER_NAME"]);
            Response.Write("<br/>");
            Response.Write(".NET解釋引擎版本:" + ".NET CLR" + System.Environment.Version);
            Response.Write("<br/>");
            Response.Write("伺服器作業系統版本:" + System.Environment.OSVersion.ToString());
            Response.Write("<br/>");
            Response.Write("伺服器IIS版本:" + Request.ServerVariables["SERVER_SOFTWARE"]);
            Response.Write("<br/>");
            Response.Write("HTTP訪問埠:" + Request.ServerVariables["SERVER_PORT"]);
            Response.Write("<br/>");
            Response.Write("虛擬目錄的絕對路徑:" + Request.ServerVariables["APPL_RHYSICAL_PATH"]);
            Response.Write("<br/>");
            Response.Write("執行檔案的絕對路徑:" + Request.ServerVariables["PATH_TRANSLATED"]);
            Response.Write("<br/>");
            Response.Write("Session總數:" + Session.Contents.Count.ToString());
            Response.Write("<br/>");
            Response.Write("Application總數:" + Application.Contents.Count.ToString());
            Response.Write("<br/>");
            Response.Write("快取Cache總數:" + Cache.Count.ToString());
            Response.Write("<br/>");
            Response.Write("伺服器主機:" + Request.ServerVariables["HTTP_HOST"]);
            Response.Write("<br/>");
            Response.Write("伺服器區域語言:" + Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"]);
            Response.Write("<br/>");
            Response.Write("訪客資訊:" + Request.ServerVariables["HTTP_USER_AGENT"]);
            Response.Write("<br/>");
            Response.Write("伺服器CPU個數:" + System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")); 
            Response.Write("<br/>");
            Response.Write("伺服器CPU型別:" + System.Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")); 

你也許會問 HTTP_HOST 和 SERVER_NAME 的值是一樣的,它們之間有什麼區別?
通常伺服器預設埠為80,HTTP_HOST將省略不顯示埠號。如果伺服器是非80埠,則HTTP_HOST顯示埠號。
簡單的說就是: HTTP_HOST = SERVER_NAME:SERVER_PORT

相關文章