IIS Security for Printing

Discussion in 'ASP .Net Security' started by Brian, Feb 8, 2007.

  1. Brian

    Brian Guest

    Hi,

    We have an asp.net 2 application that prints a file (integrated security and
    impersonation is configured
    for the application). The application is a non-windows version of:
    http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

    It all works fine on IIS 5 (XP) and 6 (2k3) when printing to a local printer
    defined on the IIS server. However when setting the printer to a network
    printer the IIS server fails when accessing the web site from a remote
    computer (that is, it works when accessing the pages on the IIS computer but
    not from another computer).

    Does anyone have any ideas of the security settings necessary to enable
    network printer access?

    Brian

    EVENT - SYSTEM
    --------------------------------------------------------------------------------------------------
    Event Type: Warning
    Event Source: Print
    Event Category: None
    Event ID: 20
    Date: 8/02/2007
    Time: 1:15:14 PM
    User: NT AUTHORITY\SYSTEM
    Computer: computer
    Description:
    Printer Driver FX ApeosPort-II C4300 PCL 6 for Windows NT x86 Version-3 was
    added or updated. Files:- fx6raeim.dll, fx6raeiu.dll, fx6rae.ddd,
    fx6rae.hlp, fx6rajdm.dll, fx6raeir.xrs, fx6raex.dll, fx6raex.exe,
    fxzddmif.dll, fxzdhb32.dll, fxzpmc3.dll, fxzadcmn.dll, fxzarl32.dll,
    fxz430a3.dll, fxlzjnie.dll, fxlznie1.dll, fx6rae.cfg, fx6rae.tbl,
    fx6rae.cnt, fx6rae.xrs, fx6rae.cdd, fx6rbe.ddd, fx6rce.ddd, fx6rde.ddd,
    fx6ree.ddd, fx6rfe.ddd.

    EVENT - APPLICATION
    --------------------------------------------------------------------------------------------------
    Event code: 3005
    Event message: An unhandled exception has occurred.
    Event time: 8/02/2007 1:15:16 PM
    Event time (UTC): 8/02/2007 3:15:16 AM
    Event ID: 4ae3a3b1b39c4ff1b5734af3590eb19e
    Event sequence: 105
    Event occurrence: 6
    Event detail code: 0


    Application information:
    Application domain: /LM/W3SVC/1/Root/BatchPrint-1-128153695175334014
    Trust level: Full
    Application Virtual Path: /BatchPrint
    Application Path: C:\Data\Reports\Web\BatchPrint\
    Machine name: DELL-29

    Process information:
    Process ID: 3424
    Process name: aspnet_wp.exe
    Account name: DELL-29\ASPNET

    Exception information:
    Exception type: InvalidPrinterException
    Exception message: Settings to access printer '\\server\printer' are not
    valid.

    Request information:
    Request URL: http://dell-29/batchprint/test.aspx
    Request path: /batchprint/test.aspx
    User host address: 192.168.1.17
    User: domain\user
    Is authenticated: True
    Authentication Type: Negotiate
    Thread account name: DELL-29\ASPNET

    Thread information:
    Thread ID: 5
    Thread account name: DELL-29\ASPNET
    Is impersonating: False

    Stack trace:
    at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal()
    at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings
    pageSettings)
    at System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument
    document, PrintEventArgs e)
    at
    System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument
    document, PrintEventArgs e)
    at System.Drawing.Printing.PrintController.Print(PrintDocument document)
    at System.Drawing.Printing.PrintDocument.Print()
    at PrintingExample.Print() in
    c:\Data\Reports\Web\BatchPrint\Test.aspx.cs:line 45
    at Test.Page_Load(Object sender, EventArgs e) in
    c:\Data\Reports\Web\BatchPrint\Test.aspx.cs:line 20
    at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
    Object t, EventArgs e)
    at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
    EventArgs e)
    at System.Web.UI.Control.OnLoad(EventArgs e)
    at System.Web.UI.Control.LoadRecursive()
    at System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
     
    Brian, Feb 8, 2007
    #1
    1. Advertising

  2. Brian

    Guest

    Hi Brian,

    Did you ever resolve this issue? I've got exactly the same problem...!
     
    , Mar 5, 2007
    #2
    1. Advertising

  3. Printing from IIS

    Hi Brain,

    I am trying to print a document from asp.net which is hosted in IIS. When i print a document from asp.net application, i can able to print to the network printer. But, if i try to print the same from IIS, It hits the printer but it doesn't print

    Our network printer is Password protected. I believe when i call the printer from IIS, some security options is added and i doesn't print.

    I need a some sample to print document from IIS. Actually i'm very new to this.

    Thanks for yor help.

    Regards,
    Prabakaran



    Posted as a reply to:

    IIS Security for Printing

    Hi

    We have an asp.net 2 application that prints a file (integrated security and
    impersonation is configure
    for the application). The application is a non-windows version of
    http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.asp

    It all works fine on IIS 5 (XP) and 6 (2k3) when printing to a local printe
    defined on the IIS server. However when setting the printer to a networ
    printer the IIS server fails when accessing the web site from a remot
    computer (that is, it works when accessing the pages on the IIS computer bu
    not from another computer)

    Does anyone have any ideas of the security settings necessary to enabl
    network printer access

    Bria

    EVENT - SYSTE
    -------------------------------------------------------------------------------------------------
    Event Type: Warnin
    Event Source: Prin
    Event Category: Non
    Event ID: 2
    Date: 8/02/200
    Time: 1:15:14 P
    User: NT AUTHORITY\SYSTE
    Computer: compute
    Description
    Printer Driver FX ApeosPort-II C4300 PCL 6 for Windows NT x86 Version-3 wa
    added or updated. Files:- fx6raeim.dll, fx6raeiu.dll, fx6rae.ddd
    fx6rae.hlp, fx6rajdm.dll, fx6raeir.xrs, fx6raex.dll, fx6raex.exe
    fxzddmif.dll, fxzdhb32.dll, fxzpmc3.dll, fxzadcmn.dll, fxzarl32.dll
    fxz430a3.dll, fxlzjnie.dll, fxlznie1.dll, fx6rae.cfg, fx6rae.tbl
    fx6rae.cnt, fx6rae.xrs, fx6rae.cdd, fx6rbe.ddd, fx6rce.ddd, fx6rde.ddd
    fx6ree.ddd, fx6rfe.ddd

    EVENT - APPLICATIO
    -------------------------------------------------------------------------------------------------
    Event code: 300
    Event message: An unhandled exception has occurred
    Event time: 8/02/2007 1:15:16 P
    Event time (UTC): 8/02/2007 3:15:16 A
    Event ID: 4ae3a3b1b39c4ff1b5734af3590eb19
    Event sequence: 10
    Event occurrence:
    Event detail code:

    Application information
    Application domain: /LM/W3SVC/1/Root/BatchPrint-1-12815369517533401
    Trust level: Ful
    Application Virtual Path: /BatchPrin
    Application Path: C:\Data\Reports\Web\BatchPrint
    Machine name: DELL-2

    Process information
    Process ID: 342
    Process name: aspnet_wp.ex
    Account name: DELL-29\ASPNE

    Exception information
    Exception type: InvalidPrinterExceptio
    Exception message: Settings to access printer '\\server\printer' are not
    valid

    Request information
    Request URL: http://dell-29/batchprint/test.asp
    Request path: /batchprint/test.asp
    User host address: 192.168.1.1
    User: domain\use
    Is authenticated: Tru
    Authentication Type: Negotiat
    Thread account name: DELL-29\ASPNE

    Thread information
    Thread ID:
    Thread account name: DELL-29\ASPNE
    Is impersonating: Fals

    Stack trace
    at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal(
    at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings
    pageSettings
    at System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument
    document, PrintEventArgs e
    at
    System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument
    document, PrintEventArgs e
    at System.Drawing.Printing.PrintController.Print(PrintDocument document
    at System.Drawing.Printing.PrintDocument.Print(
    at PrintingExample.Print() in
    c:\Data\Reports\Web\BatchPrint\Test.aspx.cs:line 4
    at Test.Page_Load(Object sender, EventArgs e) in
    c:\Data\Reports\Web\BatchPrint\Test.aspx.cs:line 2
    at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
    Object t, EventArgs e
    at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
    EventArgs e
    at System.Web.UI.Control.OnLoad(EventArgs e
    at System.Web.UI.Control.LoadRecursive(
    at System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    EggHeadCafe - Software Developer Portal of Choice
    WCF Workflow Services Using External Data Exchange
    http://www.eggheadcafe.com/tutorial...a-6dafb17b6d74/wcf-workflow-services-usi.aspx
     
    prabakaran subramanian, Sep 17, 2009
    #3
  4. Brian

    Brian Taylor Guest

    Printing from IIS

    Hi Prabakaran,
    The printer needed to be local on the IIS server even if the port is an IP address and is referred to by name (string). Below is the printing code for your information - not all is applicable.
    Regards,
    Brian

    using System;
    using System.Data;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Configuration;
    using System.Collections;
    using System.Security.Principal;
    using System.Threading;
    using System.Web;
    using System.Web.Security;
    using System.Web.Services;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using BatchPrintUtility;

    //[assembly: System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.RequestMinimum, Unrestricted=true)]
    //[AspNetHostingPermission(System.Security.Permissions.SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Unrestricted)]
    public partial class Execute : System.Web.UI.Page
    {
    Thread printReports = null;

    protected void Page_Load(object sender, EventArgs e)
    {
    // check for valid page parameters
    bool ok = Request.QueryString["BatchId"] != null && Request.QueryString["printer"] != null;
    pnlForm.Visible = ok;
    pnlError.Visible = !ok;
    cvBatchId.IsValid = ok;
    if (!ok)
    return;

    // print the batch in a new background thread so that we can monitor the status
    if (!IsPostBack)
    {
    Session["Printing"] = "Start"; // initialise the session on the main thread so that it can be accessed in the printing thread
    lblResults.Text = "Printing Status" + " - " + (Session["Printing"] == null ? "null" : Session["Printing"]) + ", " + (printReports == null ? "null" : printReports.IsAlive.ToString());
    Session["Results"] = null;
    tmrResults.Enabled = true;
    printReports = new Thread(new ParameterizedThreadStart(PrintReportBatch));
    Session["Printing"] = "Starting";
    printReports.Start(Request.QueryString["printer"]);
    Session["Printing"] = "Started";
    //PrintReportBatch(Request.QueryString["printer"]);
    }
    }

    /// <summary>
    /// Print the report batch by:
    /// 1. Open the specified batch in the database
    /// 2. Get the next report from the batch
    /// 3. Stream the report from the server and print the report
    /// 4. Return the status on the print operation (in colour to the web page using AJAX)
    /// 5. Log the print operation and result (including any error message) to the log file
    /// 6. Repeat until all report have been printed
    /// </summary>
    private void PrintReportBatch(object printer)
    {
    // changes to get this thread working in the background: changes aspnet.config rather than the Impersonate option
    // changes to aspnet.config: see http://www.leastprivilege.com/CommentView.aspx?guid=4b87938a-ee1b-4bf8-994c-befbfeac9b97
    //Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); // Session["User1"] = this.Context.User.Identity.Name;
    //((WindowsIdentity)this.Context.User.Identity).Impersonate();
    //((WindowsIdentity)Thread.CurrentPrincipal.Identity).Impersonate();
    //this.Request.LogonUserIdentity.Impersonate();
    //string applicationName = "BatchPrint";
    //IUserManager userManager = GetUserManager();
    //bool authenticated;
    //authenticated = userManager.Authenticate(applicationName, userName, password);
    //if (authenticated)
    //{
    // IIdentity identity = new GenericIdentity(userName);
    // CustomPrincipal.Attach(identity, applicationName, userManager, CacheRoles);
    //}

    // initialise variables
    bool status = true;
    string report = null;
    int copies;
    string parameters;
    PrintReport printReport = new PrintReport((string) printer, this.Context.User.Identity.Name, this.Context.Request.RawUrl); // @"\\biarritz\L1 Xerox C4300"

    // open the specified batch in the database
    //sdsExecute.SelectParameters["BatchId"].DefaultValue = "1";
    //sdsExecute.SelectParameters["ReportCondition"].DefaultValue = "Week";
    SqlDataReader reports = (SqlDataReader) sdsExecute.Select(new DataSourceSelectArguments());

    // check for no reports
    if (reports == null)
    {
    Session["Printing"] = false;
    return;
    }

    // create the results table
    Table tblResults = new Table();
    TableHeaderRow thr = new TableHeaderRow();
    TableHeaderCell thc;
    TableRow tr;
    TableCell tc;
    //CellPadding="1" CellSpacing="1">
    tblResults.BorderColor = Color.Black;
    tblResults.BorderStyle= BorderStyle.Solid;
    tblResults.BorderWidth = 1;

    // create the header row for the table
    tblResults.Rows.Add(thr);
    thc = new TableHeaderCell(); thr.Cells.Add(thc); thc.Text = "#";
    thc = new TableHeaderCell(); thr.Cells.Add(thc); thc.Text = "Report";
    thc = new TableHeaderCell(); thr.Cells.Add(thc); thc.Text = "Copies";
    thc = new TableHeaderCell(); thr.Cells.Add(thc); thc.Text = "Result";
    thc = new TableHeaderCell(); thr.Cells.Add(thc); thc.Text = "Message";

    // loop through the reports
    for (int count=1; reports.Read(); count++)
    {
    // print the report
    report = reports.GetString(0);
    if (reports.IsDBNull(1))
    parameters = null;
    else
    parameters = reports.GetString(1);
    if (reports.IsDBNull(2))
    copies = 1;
    else
    copies = reports.GetInt32(2);
    if (copies > 0)
    status = printReport.RenderPrint(report, parameters, copies);
    else
    {
    status = true;
    printReport.ErrorMessage = ""; // clear the last error message
    }
    // status = true;
    //System.Threading.Thread.Sleep(2500);

    // display the results
    tr = new TableRow();
    tr.BackColor = status ? Color.Lime : Color.Red;
    tblResults.Rows.Add(tr);
    tc = new TableCell(); tr.Cells.Add(tc); tc.Text = count.ToString();
    tc = new TableCell(); tr.Cells.Add(tc); tc.Text = report;
    tc = new TableCell(); tr.Cells.Add(tc); tc.Text = copies.ToString();
    tc = new TableCell(); tr.Cells.Add(tc); tc.Text = status ? "Printed" : "Error";
    tc = new TableCell(); tr.Cells.Add(tc); tc.Text = status ? "at: " + DateTime.Now.ToString() + @", to: " + (string) printer : printReport.ErrorMessage;
    Session["Results"] = tblResults;
    }

    // finish up
    reports.Close();
    Session["Printing"] = "End";
    }

    /// <summary>
    /// Return to the batch screen
    /// </summary>
    protected void btnReturn_Click(object sender, EventArgs e)
    {
    Response.Redirect("Batch.aspx");
    }

    /// <summary>
    /// Collect and display the latest results
    /// </summary>
    protected void tmrResults_Tick(object sender, EventArgs e)
    {
    lblResults.Text = "Print status as at: " + DateTime.Now.ToLongTimeString(); // +" - " + (Session["Printing"] == null ? "null" : Session["Printing"]) + ", " + (printReports == null ? "null" : printReports.IsAlive.ToString());
    Table tblResults = (Table) Session["Results"];
    if (tblResults != null)
    udpResults.ContentTemplateContainer.Controls.Add(tblResults);
    if (Session["Printing"] == null)
    {
    lblResults.Text = "A fatal error occured with the background printing process. Please report this error on the helpdesk system.";
    tmrResults.Enabled = false;
    return;
    }
    if ((string) Session["Printing"] == "End")
    {
    lblResults.Text = "Printing Complete"; // +" - " + (Session["Printing"] == null ? "null" : Session["Printing"]) + ", " + (printReports == null ? "null" : printReports.IsAlive.ToString());
    tmrResults.Enabled = false;
    }
    }
    }




    Posted as a reply to:

    Printing from IIS

    Hi Brain,

    I am trying to print a document from asp.net which is hosted in IIS. When i print a document from asp.net application, i can able to print to the network printer. But, if i try to print the same from IIS, It hits the printer but it doesn't print

    Our network printer is Password protected. I believe when i call the printer from IIS, some security options is added and i doesn't print.

    I need a some sample to print document from IIS. Actually i'm very new to this.

    Thanks for yor help.

    Regards,
    Prabakaran

    EggHeadCafe - Software Developer Portal of Choice
    WCF Workflow Services Using External Data Exchange
    http://www.eggheadcafe.com/tutorial...a-6dafb17b6d74/wcf-workflow-services-usi.aspx
     
    Brian Taylor, Sep 18, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,514
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. JustSomeGuy
    Replies:
    13
    Views:
    514
    msalters
    Dec 9, 2004
  3. iffy agbim
    Replies:
    1
    Views:
    110
    Mark Andrews
    May 24, 2004
  4. iffy agbim
    Replies:
    0
    Views:
    104
    iffy agbim
    May 21, 2004
Loading...

Share This Page