tags:

views:

467

answers:

2

I've created a windows forms control, which is hosted in a web page viewable with Internet Explorer.

My control reads from a com port and it writes to the event log. Both of these operations by default fail when the framework requests proper permissions. This web application will always be running in the intranet zone, how do I enable these operations?

Serial port code bits & error:

private System.IO.Ports.SerialPort portCardReader_m = new System.IO.Ports.SerialPort();
portCardReader_m.PortName = value;
portCardReader_m.Open();  //Exception here

Request for the permission of type 'System.Security.Permissions.SecurityPermission,mscorlib, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089 failed.

Event Log code bits & error:

System.Diagnostics.EventLog pEventLog = new System.Diagnostics.EventLog("Application", ".", this.GetType().FullName);
pEventLog.WriteEntry(this.Text, System.Diagnostics.EventLogEntryType.Error); //Exception Here

Request for the permission of type 'System.Diagnostics.EventLogPermission,System, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089 failed.

Code to embed my control in the browser:

<object width="600px" height="300px" id="objCardReader" classid="cardreader.dll#CardReader">
    <param name="Text" value="Testing" />
    <param name="PortName" value="COM5" />
</object>
+1  A: 

You would need to create an installer or have your users grant a higher trust level for your website. These settings are editable under Microsoft .NET Framework configuration. under Administrative Tools. You can also take a look at Chris Sells Wahoo which uses an installer to grant these permissions

Aaron Fischer
A: 

I've struggled with this in the past and tried to elevate permissions using caspol and it was a real pain. I ended up converting it to a click once app in 30 minutes and never had a problem with it since.

duckworth