A network connected printer is not available in ASP.Net

I have an ASP.Net 4.0 web application running on IIS 7.5, I can get a list of installed printers using the command System.Drawing.Printing.PrinterSettings.InstalledPrintersand assign each report in the application to any printer listed above!

On a server on which all full-featured privileges are installed , there may be several network-connected printers . Everything works fine until the user account of the application exits from the window., At the moment System.Drawing.Printing.PrinterSettings.InstalledPrintersonly local printers are returned, network printers are not specified!

I tried to impersonate the ASP.Net process for a user with access to network printers in the following ways, but without success:

  • I configured the application pool Process Modelto run as a specific user identity.
  • I personified the application identifier to a specific user in Web.Config:

    <identity impersonate="true" userName="user" password="pass"/>

  • And finally, code impersonation using the advapi32.dllAPI is implemented

In all the above methods, WindowsIdentityreturns the true username when printing:

System.Security.Principal.WindowsIdentity.GetCurrent().Name

But impersonation doesn't seem to be a problem here, as soon as the user logs out, all network printers are gone!

Does anyone know how to solve this? Is there a way to access network printers even if the user is not registered?

+5
source share
2 answers

, , , , !

System.Printing.PrintServer GetPrintQueues, , :

PrintServerUNCName - UNC , \\MyServerName

var printers = new PrintServer("PrintServerUNCName").GetPrintQueues()
    .Where(t =>
    {
        try { return t.IsShared && !t.IsNotAvailable; }
        catch { return false; }
    })
    .Select(t => t.FullName)
    .ToArray();
+3

, . , , UNC.

ASP.NET

0

All Articles