62,046
社区成员
发帖
与我相关
我的任务
分享
//获取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" />
要放到这里来执行