3

I have an MVC application in which users are able to upload files. Before I write the uploaded file, I create a directory according to date time. I start off with C:\ApplicationName and end up with C:\ApplicationName\20111001\Filename.ext when the upload is completed (in theory).

My problem on my local Windows 7 machine is that I can not write the file.

I get an "access denied" exception no matter which user I give full access to the directory. The strange thing is that the date directory gets created just fine.

I have given the following users full access:

  • [Current logged in user]
  • NETWORK SERVICE
  • IUSR
  • IIS_IUSRS
  • Guests
  • Everyone

Without any success. I really don't understand what is going on here. When I give Everyone full access, I should be able to create a file right?

PS: I use Visual Studio 2010 and ASP.NET Development Server straight out of the box.

Rezaeimh7
  • 1,467
  • 2
  • 23
  • 40
TheGuest
  • 415
  • 1
  • 4
  • 14
  • I think the fact that you're using MVC isn't part of the problem. Not sure (I don't know much about MS web server permissions yet), but you might also need to set the application's trust level. When you deploy to IIS, you'll need to check your app pool to see which user your code is running as. – Merlyn Morgan-Graham Oct 01 '11 at 19:53
  • Post the line of code that writes the file, exact value of the file name (first try to use harcoded value like @"C:\ApplicationName\20111001\Filename.ext") and exception information. Otherwise should work since you are able to create folder. – Alexei Levenkov Oct 01 '11 at 20:11
  • I have done what you said: System.IO.File.WriteAllBytes(@"C:\ApplicationName\20111001\Filename.ext", new byte[1] { 0 }); But is still get the exception, "Access to the path 'C:\ApplicationName\20111001' is denied" – TheGuest Oct 02 '11 at 17:33

4 Answers4

1

I am not running IIS, I am running the watered down version "ASP.NET Development Server". So I am quite limited

The problem is that in order for you to write to the file directory from the application you will need to run Visual Studio as Administrator.

Windows 7 is preventing the process from going outside of its sandbox because it is running with limited privileges. This is true even if your account is the administrator.

Chad
  • 1,512
  • 1
  • 16
  • 40
1

Check the permissions of the parent folder and make sure they are inheritable, you can check this on the advance options window.

ryudice
  • 36,476
  • 32
  • 115
  • 163
1

This might help a bit... probably application pool permission is the culprit here:

IIS AppPoolIdentity and file system write access permissions

Community
  • 1
  • 1
Anas Karkoukli
  • 1,342
  • 8
  • 13
0

Just had the same problem myself. By default IIS7 AppPools use AppPoolIdentity. Just open up your AppPools in IIS Management Console, select the one you are having problems with, choose Advanced Settings and under Process Model change Indentity to Built-in Acoount > NetworkService. Since you have already granted NETWORK SERVICE acces to your folder everything should work.

juhan_h
  • 3,965
  • 4
  • 29
  • 35
  • I am not running IIS, I am running the watered down version "ASP.NET Development Server". So I am quite limited. – TheGuest Oct 02 '11 at 17:36