accessing serial port from web page

The new security model on framework 2.0 makes it very difficult to access the resources from the local machine. There is a very good kbase article on the subject

http://support.microsoft.com/kb/839300

"How to use the AllowPartiallyTrustedCallers attribute to call an assembly that has a strong name from a Web page by using Visual C# .NET or Visual C# 2005"

Hovever this article does not address the issue of the aquiring the security to access a serial port.

I have tried to decifer the necessary permissions needed in code to adapt the code in this article to no avail.

I suspect it is something like

SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.Execution);

sp.Assert();

but this does not work.

Does anyone any experience or knowlege of how to set the permissions in code to access a serial port from a web browser

Thanks,

PatC



Answer this question

accessing serial port from web page

  • GunaChinna

    And the magic trick IS !!!
    After one week and several hundred compile roundtrips ....
    Drum roll ....

    [SuppressUnmanagedCodeSecurityAttribute()]

    put this in the namespace of the class that you are calling from the web page.

    Then do a

    SecurityPermission sx = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

    sx.Assert();

    you can then access the serial port on the client machine from the browser.

    Typical code being ;

    serialPort1.PortName = "COM6";
    serialPort1.BaudRate = 2400;
    serialPort1.Parity = System.IO.Ports.Parity.Even;
    serialPort1.DataBits = 7;
    serialPort1.StopBits = System.IO.Ports.StopBits.One;
    serialPort1.Open();
    serialPort1.ReadExisting();


    thanks to all who answered my various posts.

    PatC


  • accessing serial port from web page