Getting Access denied trying to read a file in App_Data in a ASP.NET project - Any pointers?

一曲冷凌霜 提交于 2019-12-13 02:05:44

问题


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.

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.

The code to open it is simple:

FileStream fs = new FileStream(Server.mapPath(s), FileMode.Open);

Where s is defined as '~/App_Data/myfile.xml

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).

I've also tried running aspnet_regiis.exe /s as per some suggestions out there.

This has me baffled.


回答1:


Actually, I think I found it. I needed to open the file as follows:

new FileStream(Server.MapPath(s), FileMode.Open, FileAccess.Read);



来源:https://stackoverflow.com/questions/2128327/getting-access-denied-trying-to-read-a-file-in-app-data-in-a-asp-net-project-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!