获取访问被拒绝试图读取的App_Data在ASP.NET项目中的文件 - 任何指针? [英] Getting Access denied trying to read a file in App_Data in a ASP.NET project - Any pointers?
问题描述
我已经存储在程序App_Data的XML文件,该文件仅用于阅读在启动一些配置。当我尝试我的code中打开它,我去......被拒绝的消息路径的访问。
I've an XML file stored in App_Data which is only used to read some configuration on startup. When I attempt to open it within my code, I get an Access to the path ... is denied message.
我无法理解为什么,以及如何解决它。我想从理论上讲,我应该改变的文件(目录)的权限,但这并没有改变任何东西。
I'm having trouble understanding why, and how to solve it. I guess in theory I should alter the permissions on the file (and directory), but this hasn't changed anything.
为了让多一点背景:
1.它与项目捆绑一个文件,因此通过VS2008创建的安装过程中安装它写入到正确的位置。我不认为我需要做什么不寻常的安装后使得ASP.NET应用程序将有机会获得。
2.当我试着发布这个地方,我已经没有任何问题。 - 这只是一个测试的Windows 2003服务器上。
3.我已经跑了一个简单的页面,了解IIS的有效用户 - 这是NT AUTHORITY \\ NETWORK SERVICE。我试着授予完全访问,以该用户这个文件,它仍然无法正常工作。
To give a bit more background: 1. Its a file bundled with the project, so the setup created by VS2008 writes it to the correct place during install. I didn't think I'd need to do anything unusual post install such that the ASP.NET application would have access. 2. When I've tried publishing this locally, I've not had any problems. - This is only on a test Windows 2003 server. 3. I've ran a simple page to understand the effective user of IIS - It is NT AUTHORITY\NETWORK SERVICE. I tried granting "Full Access" to this user to this file, and still it doesn't work.
在code打开它很简单:
The code to open it is simple:
FileStream fs = new FileStream(Server.mapPath(s), FileMode.Open);
其中S是定义为〜/ App_Data文件/ myfile.xml中
Where s is defined as '~/App_Data/myfile.xml
我甚至复制和粘贴的完整路径和放大器;文件名(从除外),并试图目录就可以了,这的确是present(避开例如错字)。
I've even copied and pasted the full path & filename (from the exception) and tried "dir" on it, and it is indeed present (to get around a typo for example).
我也试过根据一些建议,在那里ASPNET_REGIIS.EXE / s的运行。
I've also tried running aspnet_regiis.exe /s as per some suggestions out there.
这有我百思不得其解。
推荐答案
其实,我觉得我找到了。我需要打开文件如下:
Actually, I think I found it. I needed to open the file as follows:
新的FileStream(使用Server.Mappath(S),FileMode.Open,FileAccess.Read);
这篇关于获取访问被拒绝试图读取的App_Data在ASP.NET项目中的文件 - 任何指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!