Hello,
I'm trying to to print under an impersonated context from a web application. I use impersonation, so that the print follow-me system is able to identify the user that is printing.
using (var impersonation = ((WindowsIdentity)HttpContext.User.Identity).Impersonate())
{
var printIdentity = WindowsIdentity.GetCurrent().Name;
var installedPrinters = System.Drawing.Printing.PrinterSettings.InstalledPrinters;
var printer = new Printer(installedPrinters[4]);
}
Listing the installed printers works with this code.
The call to new Printer() fails:
[PrintingException: Print Job Watcher could not be started. Failed to create job change handles.]
w.a(Char* ) +808
j..ctor(String , Char* ) +208
r.a(String ) +374
ceTe.DynamicPDF.Printing.Printer..ctor(String printerName) +16
ServersidePrinting.Controllers.HomeController.Print() in c:\development\prototypes\ServersidePrinting\ServersidePrinting\Controllers\HomeController.cs:27
lambda_method(Closure , ControllerBase , Object[] ) +113
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +242
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +12
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +139
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +112
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +452
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +37
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
Is this supported, is there anything I need to be aware of when using the Printer impersonated
Impersonation
Re: Impersonation
Support · Jan 16, 2015Hello,
Our development team looked into this further and found that the error you are getting (when printing by impersonating a user) is caused due to an issue in the Windows api that our product internally uses to print.
The workaround for this is to create the Printer object before you impersonate the user. Then impersonate the user and create the PrintJob object and call Print().
Thanks,
ceTe Software Support Team.