I am working on a project which deals with Arduino. We developed a forms application in C# for navigating a car. Navigation in forms application works correctly, without any problems.
Here is the corresponding code for driving the car (this is the whole forms application).
ASP.NET website is unable to communicate with Arduino. Pressing any button to navigate the car does not work.
You realise you need to either re-open the serial port with every request, or store the serial port object in the session & retrieve it at the start of every request?
From your code, clicking any button won't do anything because the serial port isn't open, or in the case of button2, open but nothing is sent.
Despite what it looks like, asp.net is not stateful. You need to rebuild the state everytime