Access to the port 'COM4' is denied

I am using arduino, and I made an ASP.net page to communicate with it. I connected arduino to serial-port COM4. When I run the ASP.net website, I get the following error:

Exception Details: System.UnauthorizedAccessException: Access to the port 'COM4' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

I truely have no idea how to fix this problem. PS: I first did a windows form application and it worked. So there is nothing else using the COM4.

Thanks in advance.

I am using arduino, and I made an ASP.net page to communicate with it. I connected arduino to serial-port COM4. When I run the ASP.net website, I get the following error:

Exception Details: System.UnauthorizedAccessException: Access to the port 'COM4' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

I truely have no idea how to fix this problem. PS: I first did a windows form application and it worked. So there is nothing else using the COM4.

Thanks in advance.

I truely have no idea how to fix this problem.

The directions are right there:

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Did you follow them?

Crossposted. Reported to moderators.

which file do they mean by "file in explorer" ? do they mean the file containing the asp.net? or the asp.net file itself?

chill man !! it's not like i am spamming the website.. i just didn't know which category my question best goes. so take it easy

do they mean the file containing the asp.net? or the asp.net file itself?

The .exe file.

chill man !! it's not like i am spamming the website.. i just didn't know which category my question best goes. so take it easy

Pick ONE. If you don't get responses, ask a moderator to move it.

ok didn't know that.. new to the forums concept...

i don't have a file with the extension .exe in my project

What version of IIS are you uing. By default I imagine that IIS blocks acccess to the COM ports for security reasons, so you'll probably need to enable this yourself. You could also try changing the ASP user, by default ASP creates a user on your PC with limited rights that it uses, but you can change it so that it uses an administrator account, though this has obvious security issues.

apparently my computer didn't support IIS so I downloaded iis 7.5 express.. after installing it, I couldn't find out how to use it. it doesn't even show in my control panel\administrative tools.

zahidaoui:
apparently my computer didn't support IIS so I downloaded iis 7.5 express.. after installing it, I couldn't find out how to use it. it doesn't even show in my control panel\administrative tools.

If you open up the start menu and type in "iis" it should find the "Internet Information Services (IIS) Manager", in there look for "Application Pools", and select "Default Application Pool", in the advanced settings for this set the Identity to "LocalSystem", this should make your web server act as though it is runnning as a local user on the computer (with all of their rights).

Hmmm, ignore my last post for the moment, I'm running IIS 7 on my PC, and I've just done a very quick and dirty test using a virtual COM port I have installed on my PC, it seems to work first time for me without having to change permissions :frowning:
I did notice though the first time I ran it I forgot to close the serial port at the end of my code, and this actually blocked any further conections, with the same access denied error. Try killing the iis process (I think it's called w3wp.exe) and checking that your code will always close the serial port after each transaction, and this will hopefully work!!!
So you will have something like:

            SerialPort port = new SerialPort("COM8", 9600, Parity.None, 8, StopBits.One);
            try
            {
                port.Open();
                port.WriteLine("Give me data!!!");
                string data = port.ReadLine();
                Response.Write(data);
            }
            finally
            {
                if(port.IsOpen)
                    port.Close();//<---this is the important bit!!!
            }

Please don't cross post! Threads merged.