ASP.NET IIS server side printing fails

AlBaraa Sh picture AlBaraa Sh · Jan 1, 2014 · Viewed 13.8k times · Source

I'm building an ASP.NET application that requires printing using PrintDocument method:

PrintDocument.Print()

Printing works properly in development env with IIS express. when publishing it to an intranet IIS server, printing fails, which I think is caused by permission issue for aspnet working process.

I tried to do the following with no success:

  • I created an application pool in integrated pipeline mode for an admin local user with load user profile option set to true
  • I moved the application to the new created application pool
  • I added <identity impersonate="true" username="username" password="*****"/> in web.config file
  • An error appeared stating that: An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode so I added <validation validateIntegratedModeConfiguration="false"/> to <system.webServer> section.

Any help please?

Answer

Darin Dimitrov picture Darin Dimitrov · Jan 1, 2014

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.

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.

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.