Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在IIS上使用应用程序池标识查询ASP.NET中的Win32_打印机时,权限被拒绝_C#_Asp.net_Iis_Printing - Fatal编程技术网

C# 在IIS上使用应用程序池标识查询ASP.NET中的Win32_打印机时,权限被拒绝

C# 在IIS上使用应用程序池标识查询ASP.NET中的Win32_打印机时,权限被拒绝,c#,asp.net,iis,printing,C#,Asp.net,Iis,Printing,我正在使用应用程序池标识Windows 2016服务器计算机在IIS上的ASP.net代码中查询Win32_打印机。在其中一台服务器上,我收到拒绝访问错误。该代码在其他服务器上运行良好。我比较了两台服务器,但找不到权限上的差异。要进行此呼叫,我需要向IIS应用程序池标识用户授予哪些权限?下面是代码片段 使用 示例显示在: 您能否确认在其他服务器上,应用程序池标识设置为ApplicationPoolIdentity,而不是其他自定义或预定义标识(例如LocalServices),这将向客户端返回w

我正在使用应用程序池标识Windows 2016服务器计算机在IIS上的ASP.net代码中查询Win32_打印机。在其中一台服务器上,我收到拒绝访问错误。该代码在其他服务器上运行良好。我比较了两台服务器,但找不到权限上的差异。要进行此呼叫,我需要向IIS应用程序池标识用户授予哪些权限?下面是代码片段

使用

示例显示在:


您能否确认在其他服务器上,应用程序池标识设置为ApplicationPoolIdentity,而不是其他自定义或预定义标识(例如LocalServices),这将向客户端返回web服务器的打印机列表。你确定要这样吗?@Mohsin Mehmood,是的。标识设置为ApplicationPoolIdentity。另外,将其设置为LocalService实际上会显示打印机。但我不想使用LocaService。相反,我想授予ApplicationPoolIdentity或IIS_USR查询打印机列表的权限。@ManojChoudhari,yes Manoj。我们希望用户从列表中选择打印机并从服务器打印文档。
        public static List<string> GetPrinterNames()
    {
        var query = new System.Management.ObjectQuery("SELECT * FROM Win32_Printer");
        var searcher = new System.Management.ManagementObjectSearcher(query);
        var printerList = new List<string>();
        foreach (var dummyPrinterObject in searcher.Get())
        {
            printerList.Add(dummyPrinterObject["DeviceID"] as string);
        }

        return printerList;
    }
public static System.Drawing.Printing.PrinterSettings.StringCollection InstalledPrinters { get; }
private void PopulateInstalledPrintersCombo()
{
    // Add list of installed printers found to the combo box.
    // The pkInstalledPrinters string will be used to provide the display string.
    String pkInstalledPrinters;
    for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++){
        pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
        comboInstalledPrinters.Items.Add(pkInstalledPrinters);
    }
}