Error "The RPC server is unavailable" when trying to print from a web application

1.3k views Asked by At

I'm building an ASP.NET application where it prints some tags with a barcodes, the printers will be installed into local PCs and will be shared in the server where the application is hosted.

So my issue is related to the domain name, because the domain name where the printers are installed is different to the domain name where the server is. I tried to print from the local application and it prints correctly but when I try to print from the web, the following error is shown:

The RPC server is unavailable

I think it's a security issue, I tried to supplant the user that runs the application but even so the application does not works.

2

There are 2 answers

0
Ross Dargan On

Firstly, if you are printing you really shouldn't be creating a web app (or allow the user to print the barcode locally from the page).

If you must do it this way then you need to ensure that just before you execute your print code you impersonate a user that has permission on the domain to print the barcode. This code should help:-

using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
{
   ... 
   Print Code
   ...
}

The Impersonator class can be found here: http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User

0
AlainD On

My standard C# WinForms application generates the same The RPC server is unavailable error if:

  • debugging from within Visual Studio 2019, or
  • run normally by double-clicking the application in Explorer

But right-click the application, select Run as administrator, enter user credentials of an admin account...and printing works fine.

My user account is a restricted standard user, not part of the Administrator's group (something dictated by an over-zealous IT department).

Not tried the Impersonator suggestion from Ross, which sounds interesting.

HTH.