开发者

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

开发者 https://www.devze.com 2023-04-10 15:05 出处:网络
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

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 AS开发者_JAVA百科P.NET Development Server straight out of the box.


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.


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


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

IIS AppPoolIdentity and file system write access permissions


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消