是否可以在上下文用户下将文档发送到网络打印机?

时间:2019-07-12 10:00:35

标签: c# asp.net-web-api aspose network-printers

我的目标是创建可以将文档打印到网络打印机的WebAPI项目。它应该打印:  -在特定凭据下(按作业存储在数据库和端点调用中)  -在调用端点的上下文用户下

我将IIS配置为在自定义帐户下运行,并在webconfig中设置<identity impersonate="true" />

我有两个端点:

[Route("api/printer")]
public IHttpActionResult Post(PrintIncomingSettings printSettings)
{
    var downloadedFile = Download(printSettings.DocumentUrl);
    using (var stream = downloadedFile.Stream)
    {
        var creds = new UserCredentials("domainName", printSettings.UserLogin, printSettings.UserPassword);
        Impersonation.RunAsUser(creds, LogonType.Batch, () =>
        {
            DocumentPrinter.Print(downloadedFile, printSettings.PrinterName);
        });
    }
    return Ok();
}

[Route("api/printer/self")]
public IHttpActionResult PrinterSelf(PrintIncomingSettings printSettings)
{
    var downloadedFile = Download(printSettings.DocumentUrl);
    using (var stream = downloadedFile.Stream)
    {
        DocumentPrinter.Print(downloadedFile, printSettings.PrinterName);
    }
    return Ok();
}

当使用模拟时,它可以工作,但是当使用自我时,它将在应用程序池凭据下发送到打印机。

0 个答案:

没有答案