Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Okay, so I wrote this code to test the issue:</p> <pre><code>public void GetWin32_NetworkAdapter() { DataTable dt = new DataTable(); dt.Columns.Add("AdapterName", typeof(string)); dt.Columns.Add("ServiceName", typeof(string)); dt.Columns.Add("AdapterType", typeof(string)); dt.Columns.Add("IPEnabled", typeof(bool)); dt.Columns.Add("MacAddress", typeof(string)); //Try getting it by Win32_NetworkAdapterConfiguration ManagementClass mgmt = new ManagementClass("Win32_NetworkAdapter"); EnumerationOptions options = new EnumerationOptions(); options.EnumerateDeep = true; ManagementObjectCollection objCol = mgmt.GetInstances(options); foreach (ManagementObject obj in objCol) { DataRow dr = dt.NewRow(); dr["AdapterName"] = obj["Caption"].ToString(); dr["ServiceName"] = obj["ServiceName"].ToString(); dr["AdapterType"] = obj["AdapterType"]; dr["IPEnabled"] = (bool)obj["IPEnabled"]; if (obj["MacAddress"] != null) { dr["MacAddress"] = obj["MacAddress"].ToString(); } else { dr["MacAddress"] = "none"; } dt.Rows.Add(dr); } gvConfig.DataSource = dt; gvConfig.DataBind(); } </code></pre> <hr> <p>When it's run on a physical IIS box I get this: <a href="http://img14.imageshack.us/img14/8098/physicaloutput.gif" rel="nofollow noreferrer">Physical IIS server http://img14.imageshack.us/img14/8098/physicaloutput.gif</a></p> <p>Same code on Virtual IIS server: <a href="http://img25.imageshack.us/img25/4391/virtualoutput.gif" rel="nofollow noreferrer">Virtual server http://img25.imageshack.us/img25/4391/virtualoutput.gif</a></p> <p><strong>See a difference?</strong> It's on the first line. The virtual server doesn't return the "AdapterType" string. Which is why the original code was failing.</p> <p>This brings up an interesting thought. If Virtual Server is supposed to be an "virtual" representation of a real IIS server, why doesn't it return the same values?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload