且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET IIS服务器端打印失败

更新时间:2023-11-27 22:31:04

我想你可能会误解一些基金会这里的概念。当您使用 PrintDocument.Print()时,您正在服务器上打印。在IIS中部署应用程序时,此打印将在托管应用程序的服务器计算机上进行。您认为您的代码在IIS Express中正常工作的原因是因为您在与测试它的客户端浏览器相同的计算机上托管您的应用程序。此外,您在您的帐户下运行了已配置打印机的应用程序。

I think you might be misunderstanding some fundamental concepts here. When you use PrintDocument.Print() you are printing on the server. When you deploy your application in IIS this printing will happen on the server computer that is hosting your application. The reason why you thought your code was working in IIS Express is because you were hosting your application on the same computer as the client browser that was testing it. Also you were running your application under your account which had a printer configured.

您无法从Web应用程序直接打印到客户端计算机。这将是一个很大的安全问题。您可以做的***的事情是使用打印 media CSS提供一些HTML文档输入 。然后,如果用户决定,他可以在他的浏览器中打印它。

You cannot print directly to the client computer from a web application. That would be a big security issue. The best you could do is provide some HTML document using a print media CSS type. Then if the user decides, he might print it in his browser.

如果另一方面你想在连接到你的网络服务器的某台打印机上打印,你将需要在IIS中配置应用程序池,以在其配置文件中配置了打印机的标识下运行。

If on the other hand you want to print on some printer that is attached to your web server, you will need to configure the Application Pool in IIS to run under an identity that has a printer configured in its profile.