I am working on a asp.net application and I want it to communicate to a arduino board via a serial port. I created a windows application that could do that and it worked, b
Try open connection and close connection on serial port block command. Ex
SerialPort COM = new System.IO.Ports.SerialPort("COM14");
protected void btnRele1_Click(object sender, EventArgs e)
{
COM.Open();
if (btnRele1.BackColor != Color.Green)
{
COM.WriteLine("1");
btnRele1.BackColor = Color.Green;
btnRele1.ForeColor = Color.White;
btnRele1.Text = "Rele 1 - ON";
}
else
{
COM.WriteLine("2");
btnRele1.BackColor = Color.LightGray;
btnRele1.ForeColor = Color.Black;
btnRele1.Text = "Rele 1 - OFF";
}
txtSerial.Text = COM.ReadLine();
COM.Close();
}
ASP.net uses a specific user account on your computer. Just like your main account you log in with. That user account has no permissions to do anything with the hardware.
To impersonate the other account in ASP.net you do the following:
Create an account that has all of the same permissions that the web user does, then in the web.config file add the following code in between the configuration tags
<identity impersonate="true" userName="somedomain\newUser" password="newUsersPassword" />
I'm guessing you're using SerialPort class to do this communication. The documentation for it states
SecurityPermission
for the ability to call unmanaged code. Associated enumeration: UnmanagedCode
Some more MSDN documentation about ASP.NET and security
If your application calls unmanaged code, it must run with Full trust. Even the least restrictive partial trust level, High, does not permit calls to unmanaged code.
You can configure the ASP.NET application's trust level like so.
Wrapping Privileged Code section suggests a workaround for granting full trust to your whole application (which could be a security risk).