且构网

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

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

更新时间:2023-11-27 22:43:58

我想你可能误解了这里的一些基本概念.当您使用 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 应用程序直接打印到客户端计算机.那将是一个很大的安全问题.您能做的***的事情是提供一些使用打印的 HTML 文档 media CSS type代码>.然后,如果用户决定,他可能会在浏览器中打印出来.

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.

另一方面,如果您想在连接到 Web 服务器的某些打印机上打印,则需要在 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.