Pra*_*bhu 10 .net c# printing asp.net system.printing
我需要将文档发送到网络打印机(\ myserver\myprinter).我正在使用System.Printing类进行打印,当它来自Windows服务时它可以正常工作,但是从ASP.NET应用程序中,它只能打印到本地打印机,而不能打印到网络打印机.我得到的错误是"打印机名称无效"这是我用来获取打印机名称:
public string PrinterName
{
using (LocalPrintServer server = new LocalPrintServer())
return server.GetPrintQueue(@"\\myserver\myprinter");
}
Run Code Online (Sandbox Code Playgroud)
我有什么选择?这是权限问题吗?
默认情况下,ASP.NET应用程序在具有有限权限的特殊帐户上运行.刚刚足以提供网页服务,仅此而已.所以你必须配置ASPNET用户.
相比之下,Windows服务通常在本地系统帐户下运行(具有高权限)
您可以通过模拟或提升运行Web应用程序的用户的权限来解决凭据问题.
但是,我们通过在服务器上添加网络打印机作为打印机(在服务器上添加打印机对话框)并将作业发送到该打印机来实现.
我们像这样使用Printing.PrintDocument(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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31063 次 |
| 最近记录: |