C# MVC 尝试写入文件时访问路径被拒绝
我有一个 MVC 应用程序,用户可以在其中上传文件。在编写上传的文件之前,我根据日期时间创建一个目录。我从 C:\ApplicationName
开始,并在上传完成后(理论上)以 C:\ApplicationName\20111001\Filename.ext
结束。
我在本地 Windows 7 计算机上的问题是无法写入该文件。
无论我向哪个用户授予对该目录的完全访问权限,我都会收到“访问被拒绝”异常。奇怪的是,日期目录创建得很好。
我已授予以下用户完全访问权限:
- [当前登录用户]
- NETWORK SERVICE
- IUSR
- IIS_IUSRS
- 来宾
- 所有人
没有任何成功。我真的不明白这是怎么回事。当我给予每个人完全访问权限时,我应该能够创建文件,对吧?
PS:我直接使用 Visual Studio 2010 和 ASP.NET 开发服务器。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是,为了从应用程序写入文件目录,您需要以管理员身份运行 Visual Studio。Windows
7 正在阻止该进程超出其沙箱,因为它即使您的帐户是管理员,也会以有限的权限运行。
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.
这可能会有所帮助...可能应用程序池权限是这里的罪魁祸首:
IIS AppPoolIdentity 和文件系统写入访问权限
This might help a bit... probably application pool permission is the culprit here:
IIS AppPoolIdentity and file system write access permissions
我自己也遇到了同样的问题。默认情况下,IIS7 AppPools 使用 AppPoolIdentity。只需在 IIS 管理控制台中打开您的 AppPools,选择您遇到问题的 AppPools,选择“高级设置”,然后在进程模型下将“身份”更改为“内置帐户”> 网络服务。
由于您已经授予了对文件夹的网络服务访问权限,因此一切都应该可以正常工作。
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.