TheGuest
TheGuest

Reputation: 415

C# MVC Access to path denied when trying to write file

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:

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.

Upvotes: 3

Views: 10891

Answers (4)

Chad
Chad

Reputation: 1562

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.

Upvotes: 1

juhan_h
juhan_h

Reputation: 4011

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.

Upvotes: 0

Anas Karkoukli
Anas Karkoukli

Reputation: 1342

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

IIS AppPoolIdentity and file system write access permissions

Upvotes: 1

ryudice
ryudice

Reputation: 37366

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

Upvotes: 1

Related Questions