开发者

.Net Active-X on HTML page: Can't get MAC address

开发者 https://www.devze.com 2023-03-16 03:29 出处:网络
I try to get mac address from active-x that is placed onto HTML web page [PermissionSet(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]

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:

  1. Add Active-X Host site to "Trusted"
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号