RSS订阅优然探索
你的位置:首页 » 技术笔记 » 正文

asp.net 获取服务端信息

选择字号: 超大 标准 发布时间:2011-1-11 13:35:19 | 作者:admin | 0个评论 | 人浏览

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

using Lc.Framework.BLL.Sysadmin;
using Lc.Framework.Entity;
using Lc.Framework.Common;
using System.IO;


namespace Lc.Framework.Webadmin.Sysadmin
{
    public partial class sysinfo : Lc.Framework.Common.BasePage.BasePage
    {
        #region 页面加载

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowSystemInfo();
            }
        }

        #endregion

        #region 显示系统信息

        protected void ShowSystemInfo()
        {

            #region 数据库版本判断
            string DbType = ConfigurationManager.AppSettings["DBtype"].ToString();
            this.LiteralDbType.Text = DbType;
            string sInfo = "Data Source=192.168.0.198;Initial Catalog=LcFramework;User ID=sa;Password=sa";
            if (DbType.ToLower() == "sqlserver")
            {
                sInfo = ConfigurationManager.ConnectionStrings["SqlServer"].ToString();
                this.LiteralDbPort.Text = "1433";
                string[] sZ = sInfo.Split(";".ToCharArray());
                for (int i = 0; i < sZ.Length; i++)
                {
                    string[] sShow = sZ[i].Split("=".ToCharArray());
                    switch (sShow[0].ToLower())
                    {
                        case "data source":
                            this.LiteralDbAddr.Text = sShow[1];
                            break;
                        case "initial catalog":
                            this.LiteralDbName.Text = sShow[1];
                            break;
                        case "user id":
                            this.LiteralDbUserName.Text = sShow[1];
                            break;
                        default:
                            break;
                    }
                }
            }
            else
            {
                sInfo = ConfigurationManager.ConnectionStrings["Oracle"].ToString();
                this.LiteralDbPort.Text = "1521";
                string[] sZ = sInfo.Split(";".ToCharArray());
                for (int i = 0; i < sZ.Length; i++)
                {
                    string[] sShow = sZ[i].Split("=".ToCharArray());
                    switch (sShow[0].ToLower())
                    {
                        case "data source":
                            this.LiteralDbAddr.Text = sShow[1];
                            this.LiteralDbName.Text = sShow[1];
                            break;
                        case "user id":
                            this.LiteralDbUserName.Text = sShow[1];
                            break;
                        default:
                            break;
                    }
                }
            }
            #endregion

            #region 操作系统信息

            this.LiteralSysNet.Text = string.Concat(new object[] { Environment.Version.Major, ".", Environment.Version.Minor, Environment.Version.Build, ".", Environment.Version.Revision });

            //this.LiteralSysVersion.Text = Request.Browser.Platform.ToString();

            this.LiteralSysName.Text = Environment.OSVersion.ToString();
            this.LiteralSysPath.Text = Environment.SystemDirectory.ToString();

            this.LiteralSysNow.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            this.LiteralSysRunDate.Text = ((Environment.TickCount / 0x3e8) / 60).ToString() + "分钟";
            this.LiteralTimeOut.Text = (Server.ScriptTimeout / 1000).ToString() + "秒";

            #endregion

            #region 其他信息

            string[] achDrives = Directory.GetLogicalDrives();
            for (int i = 0; i < Directory.GetLogicalDrives().Length - 1; i++)
            {
                this.LiteralLogicDriver.Text = LiteralLogicDriver.Text + achDrives[i].ToString();
            }
            this.LiteralCpuNum.Text = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS").ToString();
            this.LiteralCpuType.Text = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER").ToString();
            this.LiteralUser.Text = Environment.UserName;
            #endregion
        }

        #endregion

    }
}

标签:asp.net 获取服务端信息  

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。