首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

一个获取服务器硬件信息的代码!求指导…

2013-05-02 
一个获取服务器硬件信息的代码!求指点……我写了 一个获取服务器 硬盘序列号 和网卡mac 地址的 代码 ,编译成

一个获取服务器硬件信息的代码!求指点……
我写了 一个获取服务器 硬盘序列号 和网卡mac 地址  的 代码 ,编译成 dll ,再后台 调用它。
调试的时候 显示是 正常的, 但是 发布成 网站 之后 ,获取到的  硬盘序列号和网卡mac 地址 却是 错误的 。
然后我把 这个 dll  拿来 在 winform  里 试了下   也是 正常的。
所以 我想 问题 应该出在  iis  里。或者其他 什么地方?
求高手 指点…………



//获取ip mac地址
public static string GetMacAddress()           
{               
    ManagementClass class2 = new ManagementClass("Win32_NetworkAdapterConfiguration");  
    foreach (ManagementObject obj2 in class2.GetInstances())  
     {  
        if (obj2["IPEnabled"].ToString() == "True")  
         {  
            return obj2["MacAddress"].ToString();  
         } 
     } 
      return null; 
}
//获取硬盘序列号
         public static string GetHardDiskSN() 
         { 
             return GetHardwareInfo(HardwareEnum.Win32_PhysicalMedia, "SerialNumber"); 
         }








服务器 硬件
[解决办法]

using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Xml;
using Galsun.Common;
using Galsun.HH.FCX.Content;
using Galsun.HH.FCX.Mode;
using System.Data;
using System.Management;


namespace Galsun.HH.FCX.Web.UI
{
    public class HttpModule : System.Web.IHttpModule
    {
        /// <summary>
        /// 实现接口的Init方法
        /// </summary>
        /// <param name="context"></param>
        public void Init(HttpApplication context)
        {
            Hard hard = Hard.GetCacheService();
            GetHardID();
        }
        /// <summary>
        /// 获取硬盘ID
        /// </summary>
        /// <returns>硬盘ID</returns>
        public static string GetHardID()


        {

            string HDInfo = "";

            ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
            ManagementClass cimobject2 = new ManagementClass("Win32_Processor");
            try
            {

                ManagementObjectCollection moc1 = cimobject1.GetInstances();

                foreach (ManagementObject mo in moc1)
                {

                    HDInfo += (string)mo.Properties["Model"].Value;
                    break;
                }
                ManagementObjectCollection moc2 = cimobject2.GetInstances();

                foreach (ManagementObject mo in moc2)
                {

                    HDInfo += (string)mo.Properties["Processorid"].Value;
                    break;
                }
            }
            catch (Exception err)
            {
                HDInfo = err.ToString();
            }
            if (System.Web.HttpContext.Current.Application["HDInfo"] == null)
            {
                System.Web.HttpContext.Current.Application.Lock();
                System.Web.HttpContext.Current.Application["HDInfo"] = HDInfo;
                System.Web.HttpContext.Current.Application.UnLock();
            }
            return HDInfo;

        }

        public void Application_OnError(Object sender, EventArgs e)
        {


            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            //if (context.Server.GetLastError().GetBaseException() is MyException)
            {
                //MyException ex = (MyException) context.Server.GetLastError().GetBaseException();
                context.Response.Write("<html><body style="font-size:14px;">");
                context.Response.Write("GL.CMS Error:<br />");
                context.Response.Write("<textarea name="errormessage" style="width:80%; height:200px; word-break:break-all">");
                context.Response.Write(System.Web.HttpUtility.HtmlEncode(context.Server.GetLastError().ToString()));
                context.Response.Write("</textarea>");
                context.Response.Write("</body></html>");
                context.Response.End();
            }

        }


        /// <summary>
        /// 实现接口的Dispose方法
        /// </summary>
        public void Dispose()
        {

        }
    }
}


<add type="Galsun.HH.FCX.Web.UI.HttpModule, Galsun.HH.FCX.Web.UI" name="HttpModule" />

要放到这里来执行
[解决办法]
这是获取站点所在主机的硬件信息。

热点排行