从 ASP.NET 打印到网络打印机 [英] Printing from ASP.NET to a network printer
问题描述
我需要将文档发送到网络打印机 (myservermyprinter).我正在使用 System.Printing 类进行打印,当它来自 Windows 服务时它工作正常,但是来自 ASP.NET 应用程序,它只能打印到本地打印机,而不是网络打印机.我得到的错误是打印机名称无效"这是我用来获取打印机名称的内容:
I need to send documents to a network printer (myservermyprinter). 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(@"\myservermyprinter");
}
我有哪些选择?这是权限问题吗?
What are my options here? Is this a permissions problem?
推荐答案
您可以通过模拟或提升运行 Web 应用程序的用户的权限来解决凭据问题.
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.
我们像这样使用了 Printing.PrintDocument(VB 中的代码)......
We used the Printing.PrintDocument like so (Code in VB)....
Public Class SpecialReportPrintJob
Inherits Printing.PrintDocument
Protected Overrides Sub OnBeginPrint(ByVal ev as Printing.PrintEventArgs)
MyBase.OnBeginPrint(ev)
Me.PrinterSettings.PrinterName = "PrinterNameUsedOnServer"
'setup rest of stuff....
End Sub
End Class
'And we then call it like so
Dim printSpecialReport as new SpecialReportPrintJob()
printSpecialReport.Print()
这篇关于从 ASP.NET 打印到网络打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!