ASP.NET 2.0 (C#) application
Using Windows authentication and impersonation
Windows Server 2003 (IIS6)
Server is a member server on a domain
Logged into server as a domain user that is in the local Administrators
group on the server
Workstation is on the same domain
Logged into the workstation as the same domain user, which is also in the
local Administrators group on the workstation
I'm having what seems like a strange problem. I have an ASP.NET 2.0 (C#)
application that is running on my Windows Server 2003 web server. In this
application, I have an .aspx page that tries to get the list of printers on
the web server (using code-behind).
When I run the application using IE on the server, it works fine and I get a
list of the printers on the server. However, when I run the application
from the workstation using IE (simply pointing the URL to the server), I
cannot get the list of printers.
I'm trying to use WMI (2 kind of different ways) to get the list of printers
on the server. Below is some of the code snippets from my project.
Web.config
<system.web>
<authenticati on mode="Windows"/>
<identity impersonate="tr ue"/>
...
</system.web>
..aspx page
(works from the server but not any workstation)
using (System.Managem ent.ManagementC lass exportedShares = new
System.Manageme nt.ManagementCl ass("Win32_Prin ter"))
{
System.Manageme nt.ManagementOb jectCollection shares =
exportedShares. GetInstances();
foreach (System.Managem ent.ManagementO bject share in shares)
{
Response.Write( "Name: " + mo["Name"].ToString());
Response.Write( "<br />");
Response.Write( "Default: " + mo["Default"].ToString());
Response.Write( "<br />");
Response.Write( "Descriptio n: " +
share["Descriptio n"].ToString());
Response.Write( "<br />");
Response.Write( "Local: " + share["Local"].ToString());
Response.Write( "<br />");
Response.Write( "Network: " + share["Network"].ToString());
Response.Write( "<br />");
Response.Write( "Shared: " + share["Shared"].ToString());
Response.Write( "<br />");
Response.Write( "Location: " + share["Location"].ToString());
Response.Write( "<br />");
Response.Write( "ServerName : " +
share["ServerName "].ToString());
Response.Write( "<br />");
Response.Write( "ShareName: " +
share["ShareName"].ToString());
Response.Write( "<br />");
}
}
..aspx page (try #2)
(works from the server but not any workstation)
System.Manageme nt.ConnectionOp tions co = new
System.Manageme nt.ConnectionOp tions();
co.Authenticati on = System.Manageme nt.Authenticati onLevel.Default ;
co.Impersonatio n = System.Manageme nt.Impersonatio nLevel.Imperson ate;
System.Manageme nt.ManagementSc ope ms = new
System.Manageme nt.ManagementSc ope("\\\\" + computer, co);
System.Manageme nt.ObjectQuery oq = new
System.Manageme nt.ObjectQuery( "SELECT * FROM Win32_Printer") ;
System.Manageme nt.ManagementOb jectSearcher mos = new
System.Manageme nt.ManagementOb jectSearcher(ms , oq);
System.Manageme nt.ManagementOb jectCollection moc = mos.Get();
foreach (System.Managem ent.ManagementO bject mo in moc)
{
Response.Write( "Name: " + mo["Name"].ToString());
Response.Write( "<br />");
Response.Write( "Default: " + mo["Default"].ToString());
Response.Write( "<br />");
Response.Write( "Descriptio n: " + mo["Descriptio n"].ToString());
Response.Write( "<br />");
Response.Write( "Local: " + mo["Local"].ToString());
Response.Write( "<br />");
Response.Write( "Network: " + mo["Network"].ToString());
Response.Write( "<br />");
Response.Write( "Shared: " + mo["Shared"].ToString());
Response.Write( "<br />");
Response.Write( "Location: " + mo["Location"].ToString());
Response.Write( "<br />");
Response.Write( "ServerName : " + mo["ServerName "].ToString());
Response.Write( "<br />");
Response.Write( "ShareName: " + mo["ShareName"].ToString());
Response.Write( "<br />");
}
Can some one please help me understand what's going on and how to resolve
this problem?
Thanks!