I try to get mac address from active-x that is placed onto HTML web page
[PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]
public string GetMacAddress()
{
var nic = NetworkInterface.GetAllNetworkInterfaces()
.FirstOrDefault(x => x.OperationalStatus == OperationalStatus.Up);
return nic == null ? null : nic.GetPhysicalAddress().ToString();
}
But this code fails with error:
System.Net.NetworkInformation.NetworkInformationPermission, System, Version=2.0.0.0...
Meanwhile code works great for de开发者_JAVA技巧sktop applications.
I guess there are some limitations with .net active-x usage.
How can I avoid that? Can I get unique and stable workstation ID from active-x any other way ?
I have found several similar issues with silverlight: Get MAC address in Silverlight
It looks there is no way to get mac address due to .net security settings except we do the following:
- Add Active-X Host site to "Trusted"
- Call on client machine: C:\Windows\Microsoft.NET\Framework\v2.0.50727\caspol.exe -machine -quiet -addgroup Trusted_Zone -site acitve-x-host-site FullTrust -name SecutityException -description "..."
Finally I decided to rewrite Active-X to C++\ATL one.
精彩评论