从ASP.NET打印到网络打印机

问题描述:

我需要将文档发送到网络打印机(\ MYSERVER \ myprinter)。我使用的是System.Printing类打印,并能正常工作时,它从一个Windows服务,而是从一个ASP.NET应用程序,它只是能够打印到本地打印机,而不是网络打印机。我得到的错误是打印机名称无效这是我使用的是哪种打印机名称:

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应用程序在其下运行的用户提升权限解决凭据的问题。

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 code)......

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()