C#Web API找不到重定向的打印机 [英] C# Web API cannot find Redirected Printer

查看:102
本文介绍了C#Web API找不到重定向的打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发在Windows Server 2012 R2的IIS 8中部署的Web API.它要求将文档从服务器打印到网络打印机.

我正在使用具有重定向打印机的RDP会话进行开发,该打印机也已设置为我的默认打印机.

我已经创建了一个虚拟的概念证明作为控制台应用程序,以了解实现该工作所必需的内容.

虚拟控制台使用以下代码查找打印机

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

作为控制台应用程序运行时,它将使用默认的重定向打印机并正常工作.

我已将此代码移至Web API并完成了

  • 将站点的应用程序池设置为在我的帐户下运行(出于测试目的)
  • 安装了Internet打印角色
  • 安装了Internet Print Client功能

完成此操作后,默认打印机不再位于已安装打印机的列表中,并且没有可用的默认打印机.

为了使IIS托管站点可以看到重定向的打印机,我还必须进行哪些其他权限/更改?

解决方案

运行IIS的帐户必须有权访问要使用的打印队列.默认情况下不是.谁维护服务器,都需要向该帐户授予所需的权限.

请注意,这将不是RDP会话中的重定向的打印机".需要在IIS服务器上配置打印机,并且根据需要运行IIS帐户才能访问它.

RDP会话是隔离的.我不相信有一种方法(至少不是一种干净的,有文件记录的稳定方法)来赋予服务器进程访问RDP会话中的资源的权限,但是您可以使用正常的打印机配置过程来授予它自己的访问权限. /p>

在服务器端代码中,您将正常打开打印机并执行所需的任何操作,因为它只是一台普通打印机.

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?

解决方案

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.

这篇关于C#Web API找不到重定向的打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆