1

I am developing a Web API that is deployed in IIS 8 on Windows Server 2012 R2. It requires that documents be printed from the Server to a network printer.

I am developing on a RDP session which has a redirected printer, this printer is also set as my default printer.

I have created a dummy proof of concept as a Console Application to userstand what is necessary to make this work.

The dummy console uses the following code to find printers

var ps = new PrinterSettings();
foreach(var p in PrinterSettings.InstalledPrinters)
{
  var name = p as string;
  Console.WriteLine(name);
}

When running as a Console application this picks up the default redirected printer and works.

I have moved this code to the Web API and done the follwoing

  • set the Application Pool of the site to run under my account (for test purposes)
  • Installed the internet Printing Role
  • Installed the Internet Print Client feature

After doing this the default printer is no longer in the list of installed printers and there is no default available.

What additional permissions/changes do I have to make in order that the IIS hosted site can see the redirected printer?

I Spink
  • 13
  • 5
  • https://blog.lextudio.com/web-application-differences-in-visual-studio-and-iis-60fec7e311b3 The printer settings are in your user session. Therefore, IIS and the web apps is session 0 cannot see them at all. – Lex Li Jul 05 '18 at 13:15
  • As I understand this then it is not possible to print from an IIS hosted web API to a network printer? – I Spink Jul 05 '18 at 13:50
  • Too early to say "not possible", but it is really difficult. Read "Exposing printer settings to the SYSTEM account" of an old SAP page, http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc00044_0250/html/dwprgnet/BEICAAJF.htm you might see what registry keys you can modify. Again, find a spare machine (or VM) for your experiments, as editing registry keys manually is risky. – Lex Li Jul 05 '18 at 13:54
  • Having read and follwoed the instructions you linked I can still see the directly installed printer however I stll cannot see the redirected printer from the RDP session – I Spink Jul 05 '18 at 14:37

2 Answers2

0

The account that IIS is running under needs to have access to the print queue you want to use. By default, it doesn't. Whoever maintains the server needs to grant the account the needed permissions.

Note that this won't be the "redirected printer" from your RDP session. The printer needs to be configured on the IIS server, and the account IIS is running as needs to have access to it.

The RDP session is isolated. I don't believe there's a way (at least not a clean, documented stable way) to give a server process access to a resource in an RDP session, however you can certainly give it it's own access using the normal printer configuration process.

From your server-side code, you would open the printer normally and do whatever you want, because it would just be a normal printer.

Terry Carmen
  • 3,720
  • 1
  • 16
  • 32
  • 1
    I had a couple of other issues that needed to be addressed but this got me 90% of the way there, the other 10% was Loading the User Profile from Rainer Schaack's post below – I Spink Jul 10 '18 at 07:22
0

Just an idea: Did you check "Load User profile" ? See

Security exceptions in ASP.NET and Load User Profile option in IIS 7.5

and

https://blogs.msdn.microsoft.com/vijaysk/2009/03/08/iis-7-tip-3-you-can-now-load-the-user-profile-of-the-application-pool-identity/

I am not an IIS expert, but had some problem many years ago with scheduled tasks not loading the user profile.

Rainer Schaack
  • 1,558
  • 13
  • 16