Guys I am getting error in the following code in trying to get mac address of client machine in asp.net c#.When I run same code on local machine it works perfectly but when I upload same code to server I get the error as shown below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Security.Policy;
using System.Management;
using System.Management.Instrumentation;
public partial class GetMac : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = "";
ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;
try
{
query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
if (mo["MacAddress"] != null)
{
id = mo["MacAddress"].ToString();
Response.Write(id+"<br/>");
}
}
}
catch (Exception ex)
{
Response.Write(ex.Source);
Response.Write(ex.Message);
}
}
}
Error is like this:
App_Web_klgxzt4kAttempt by security transparent method 'GetMac.Page_Load(System.Object, System.EventArgs)' to access security critical method 'System.Management.ManagementObjectSearcher..ctor(System.String)' failed. Assembly 'App_Web_klgxzt4k, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted.