我正在使用以下javascript代码在我的母版页中获取MAC地址。在master.cs页面后面的代码中,在Page_Load()方法中我写了“string mac = inpHide.Value.ToString();”得到那个mac地址。但是当我调试时,我只获得null值。我需要在global.asax中使用该值。有什么帮助吗?
<script type="text/javascript">
function MACAddress() {
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
var e = new Enumerator(properties);
var MACaddress = '';
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
if (p.MACAddress) {
MACaddress = MACaddress + p.MACAddress + ',';
}
}
MACaddress = MACaddress.substring(0, MACaddress.length - 1);
var hiddenControl = '<%= inpHide.ClientID %>';
document.getElementById(hiddenControl).value = MACaddress;
}
</script>
在我的母版页中:
<div><input id="inpHide" type="hidden" runat="server"/></div>