Category Archives: asp.net-web-api2

Access to the path ‘/var/www/html/mywebapp’ is denied. on mod_mono and apache

I've been trying to deploy a Web API application onto apache. I have mono 4.1.0 working on the CentOS machine and created a Visual Studio project using the empty template using the core references for web api. The only change I did to it was to add a html file index.html to the project.

When I deploy and run it, I get the following exception:

System.UnauthorizedAccessException
Access to the path '/var/www/html/mywebapp' is denied.

Description: HTTP 400.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00335] in /usr/local/src/mono/mcs/class/corlib/System.IO/FileStream.cs:290 
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in /usr/local/src/mono/mcs/class/corlib/System.IO/FileStream.cs:97 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at System.IO.FileInfo.Open (FileMode mode, FileAccess access, FileShare share) [0x00000] in /usr/local/src/mono/mcs/class/corlib/System.IO/FileInfo.cs:208 
  at System.IO.FileInfo.OpenRead () [0x00000] in /usr/local/src/mono/mcs/class/corlib/System.IO/FileInfo.cs:188 
  at (wrapper remoting-invoke-with-check) System.IO.FileInfo:OpenRead ()
  at System.Web.HttpResponse.TransmitFile (System.String filename, Boolean final_flush) [0x00007] in /usr/local/src/mono/mcs/class/System.Web/System.Web/HttpResponse.cs:1210 
  at System.Web.HttpRuntime.AppIsOffline (System.Web.HttpContext context) [0x00044] in /usr/local/src/mono/mcs/class/System.Web/System.Web/HttpRuntime.cs:321 
  at System.Web.HttpRuntime.Process (System.Web.HttpWorkerRequest req) [0x0004a] in /usr/local/src/mono/mcs/class/System.Web/System.Web/HttpRuntime.cs:443 
  at System.Web.HttpRuntime.RealProcessRequest (System.Object o) [0x00028] in /usr/local/src/mono/mcs/class/System.Web/System.Web/HttpRuntime.cs:425 
  at System.Web.HttpRuntime.ProcessRequest (System.Web.HttpWorkerRequest wr) [0x0002b] in /usr/local/src/mono/mcs/class/System.Web/System.Web/HttpRuntime.cs:504 
  at Mono.WebServer.MonoWorkerRequest.ProcessRequest () [0x00012] in /usr/local/src/xsp/src/Mono.WebServer/MonoWorkerRequest.cs:390 

Strange thing is, file permissions are correctly set as apache:

drwxr-xr-x  3 apache apache  4096 Apr 26 17:02 mywebapp

also all files under the folder are set up as correctly as I can think of:

drwxrwxr-x  2 apache apache 4096 Apr 26 17:02 bin
-rw-rw-r--  1 apache apache  103 Apr 26 16:37 Global.asax
-rw-rw-r--  1 apache apache  140 Apr 26 16:40 index.html
-rw-rw-r--  1 apache apache  498 Apr 26 16:37 packages.config
-rw-rw-r--  1 apache apache 3222 Apr 26 17:01 Web.config

Any ideas? It seems like a very simple problem but so far I haven't found a solution.

The background for this exercise is an effort to deploy a wep api app, and before I kept seeing this bug: https://bugzilla.xamarin.com/show_bug.cgi?id=21810 after deploying a web api project that uses the web api template. Now I'm attempting to exclude as much as possible to get anything working.