从 ASP.NET 打印到网络打印机
我需要将文档发送到网络打印机 (\myserver\myprinter)。我使用 System.Printing 类进行打印,当它来自 Windows 服务时它工作正常,但来自 ASP.NET 应用程序时,它只能打印到本地打印机,而不能打印到网络打印机。我收到的错误是“打印机名称无效”这是我用来获取打印机名称的内容:
public string PrinterName
{
using (LocalPrintServer server = new LocalPrintServer())
return server.GetPrintQueue(@"\\myserver\myprinter");
}
我在这里有哪些选项?这是权限问题吗?
I need to send documents to a network printer (\myserver\myprinter). I'm using the System.Printing classes to print, and it works fine when it's from a Windows Service, but from an ASP.NET app, it's only able to print to local printers, not network printers. The error I'm getting is "Printer Name is not valid" This is what I'm using to get the printer name:
public string PrinterName
{
using (LocalPrintServer server = new LocalPrintServer())
return server.GetPrintQueue(@"\\myserver\myprinter");
}
What are my options here? Is this a permissions problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过模拟或提升运行 Web 应用程序的用户的权限来解决凭据问题。
但是,我们通过将网络打印机添加为服务器上的打印机(在服务器上添加打印机对话)并将作业发送到该打印机来做到这一点。
我们像这样使用 Printing.PrintDocument (VB 中的代码)....
There are issues with credentials that you could solve by impersonation or elevating rights of the user the web app is running under.
However, we did it by adding the network printer as a printer on the server (add printer dialogue on server) and having the job sent to that printer.
We used the Printing.PrintDocument like so (Code in VB)....
默认情况下,ASP.NET 应用程序在具有有限权限的特殊帐户上运行。足以提供网页服务,仅此而已。因此,您必须配置 ASPNET 用户。
相比之下,Windows 服务通常在本地系统帐户下运行(具有高权限)
By default, an ASP.NET application runs on a special account with limited rights. Just enough to serve webpages, nothing more. So you'll have to configure the ASPNET user.
By contrast Windows services usually run under local System account (with high privileges)
ASP.Net/C# 的网络打印可以使用以下方法完成:
如果为域用户配置网络并且将打印机添加到打印服务器:
示例: PrinterSettings.PrinterName = "\\15.1.1.1\\prn001"
首先调用模拟用户,然后调用打印函数,如下所示:
The Network Printing from ASP.Net/C# can be done using:
If the Network is configured for Domain Users and Printer is added to print server:
Example: PrinterSettings.PrinterName = "\\15.1.1.1\\prn001"
First make an call to impersonate the user and then call the print function that would look like below: