Security policy prevents my usercontrol to print on the web RRS feed

  • Question

  • I hope this is the right place to post this. Basicly I'm trying to make a print function that will select a printer, papersize and margin for the user and print. I get a error message related to the security to .NET and what client run controller on the web page is allowed to do.

    Alright from the start, I made a simple Windows Form Control Library, with a button and the click event will print out a few letters. It all works when I debug the windows control and run it as a application localy and click the button. I then implement it in my asp.net site (look at this article to see how I did it: http://www.beansoftware.com/ASP.NET-Tutorials/Place-Windows-Control-To-Web-Form.aspx ), when I then run the asp.net site and click the button do I get this error message:

    "Application attempted to perform an operation not allowed by the security policy ... bla bla bla ... Request for the permission of type 'System.Drawing.Printing.PrintingPermission, System.Drawing.Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed."

    My question is how to bypass this? Those computers that will run this small app will I be able to go in and edit the setting to their .NET security if it's posible to fix it this way? if so how? Is there other ways to bypass this problem?

    Detailes on error message:
    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.
    ************** Exception Text **************
    System.Security.SecurityException: Request for the permission of type 'System.Drawing.Printing.PrintingPermission, System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at System.Drawing.Printing.PrinterSettings.set_PrinterName(String value)
       at TestAgain.UserControl1.button1_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    The action that failed was:
    The type of the first permission that failed was:
    The Zone of the assembly that failed was:
    ************** Loaded Assemblies **************
        Assembly Version:
        Win32 Version: 2.0.50727.3069 (QFE.050727-3000)
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
        Assembly Version:
        Win32 Version: 2.0.50727.3069 (QFE.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/
        Assembly Version:
        Win32 Version: n/a
        CodeBase: http://localhost:38584/TestUserCont/TestAgain.dll
        Assembly Version:
        Win32 Version: 2.0.50727.3069 (QFE.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/
        Assembly Version:
        Win32 Version: 2.0.50727.3069 (QFE.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/
        Assembly Version:
        Win32 Version: 2.0.50727.3069 (QFE.050727-3000)
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Accessibility/
        Assembly Version: 7.0.3300.0
        Win32 Version: 7.0.3300.0
        CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.mshtml/7.0.3300.0__b03f5f7f11d50a3a/Microsoft.mshtml.dll
    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    For example:
        <system.windows.forms jitDebugging="true" />
    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.
    Wednesday, October 28, 2009 9:14 AM


All replies