How to: Print from ASP.Net on a network server

February 15, 2007 at 11:14 pm (.net, Asp.net, Asp.net 2.0, Windows)

Yesterday we had a small problem with a project of ours. We have a reporting system that server side will process the report and if configured it will print this on a printer somewhere in the network.

When we first tried this every time we printed to a network attached printer we got an error saying that we did not have access to this printer. This behavior is actually normal if you think about it. The server side code runs through an ASP.NET Web Service which in our case runs under it’s native aspnet account. Since this is a local account it does not have access to the network printer.

A solution could be impersonation or just simply make sure the web service runs as a dedicated domain account that has access. This however was not an option for us so we had to look for something else.

The solution I came up with was creating a local printer, but instead of letting it print to a local port like LPT1 I created a new standard TCP/IP port. This allows you to enter an IP and port for the networked printer. The advantage is that this printer is a local printer which requires no authentication at all, so asp.net can use it to print without knowing that it is actually being sent to a network printer.

Post a Comment