托管到 iis 时无法访问打印机

编程入门 行业动态 更新时间:2024-10-27 10:32:01
本文介绍了托管到 iis 时无法访问打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 MVC 中使用 rdlc 报告,在 Visual Studio 中运行时打印操作完美,但是当发布到在同一台机器上设置的 iis 时,打印操作没有发生.但是当我以 pdf 格式返回报告时报告在那里,我可以使用javascript打印文件.但我实际上不需要显示报告而是想从服务器打印.谢谢提前帮助

I am using rdlc report in MVC,Printing operation works perfectly when running in visual studio, but when published to iis which is set up in the same machine,printing operation is not taking place.But when I return the report as pdf the report it is there,and I can print the file using javascript.But I actually need not want to display the report but want to print from server..Thanks For help in advance

public ActionResult GenerateOrder() { try { LocalReport report = new LocalReport(); report.ReportPath = (Server.MapPath("~/Reports/Report1.rdlc")); Export(report); Print(); } catch (Exception Ex) { } return View(); } private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) { Stream stream = new MemoryStream(); m_streams.Add(stream); return stream; } private void Export(LocalReport report) { string deviceInfo = @"<DeviceInfo> <OutputFormat>EMF</OutputFormat> <PageWidth>8.5in</PageWidth> <PageHeight>11in</PageHeight> <MarginTop>0.25in</MarginTop> <MarginLeft>0.25in</MarginLeft> <MarginRight>0.25in</MarginRight> <MarginBottom>0.25in</MarginBottom> </DeviceInfo>"; Warning[] warnings; m_streams = new List<Stream>(); report.Render("Image", deviceInfo, CreateStream, out warnings); foreach (Stream stream in m_streams) stream.Position = 0; } private int m_currentPageIndex; private IList<Stream> m_streams; private void PrintPage(object sender, PrintPageEventArgs ev) { try { Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]); // Adjust rectangular area with printer margins. Rectangle adjustedRect = new Rectangle( ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX, ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY, ev.PageBounds.Width, ev.PageBounds.Height); // Draw a white background for the report ev.Graphics.FillRectangle(Brushes.White, adjustedRect); // Draw the report content ev.Graphics.DrawImage(pageImage, adjustedRect); // Prepare for the next page. Make sure we haven't hit the end. m_currentPageIndex++; ev.HasMorePages = (m_currentPageIndex < m_streams.Count); } catch (Exception ex) { } } private void Print() { if (m_streams == null || m_streams.Count == 0) throw new Exception("Error: no stream to print."); PrintDocument printDoc = new PrintDocument(); if (!printDoc.PrinterSettings.IsValid) { throw new Exception("Error: cannot find the default printer."); } else { PrinterSettings pset = new PrinterSettings(); printDoc.PrintPage += new PrintPageEventHandler(PrintPage); m_currentPageIndex = 0; printDoc.PrinterSettings.PrinterName = pset.PrinterName; printDoc.Print(); } }

推荐答案

我想你想从服务器本身打印页面.检查您的应用程序在其下运行的身份.如果它在默认帐户下运行,请将其更改为您的帐户或具有打印机访问权限的其他帐户.

I think you want to print the page from Server itself. Check the Identity under which your application is running. If it is running under default account then change it to either your account or to a different account that has printer access.

转到 IIS,(a) 首先找到您的应用正在使用的应用程序池(b) 然后转到Application Pool详细信息并找到它正在使用的Identity.(c) 将此身份更改为您/其他具有打印机访问权限的帐户.

Go to IIS, (a) First find the Application Pool your app is using (b) And then go to Application Pool details and find the Identity it is using. (c) Change this Identity to your/some other account that has printer access.

更多推荐

托管到 iis 时无法访问打印机

本文发布于:2023-11-01 22:52:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:打印机   无法访问   iis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!