iis-express 文件访问权限
我正在运行 iis express 7.5 上托管的 wcf 服务。 在服务内部,我有一个服务操作需要在文件系统上写入文件,但是当它尝试这样做时,我遇到了异常。
我正在将文件写入到托管项目的完全相同的文件夹中,方法是: 字符串 filePath = HttpContext.Current.Server.MapPath(".");
但我不断收到此异常:
DirectoryNotFoundException - “无法找到路径 C:\websites 的一部分....
似乎我的 iis express 无权写入文件。 如果是这样,我该如何授予它许可?
谢谢!
I'm running a wcf service hosted on iis express 7.5.
Inside the service, i have a service operation that needs to write a file on the filesystem, but when it tries to do so, i'm getting an exception.
i'm writing the file to the exact same folder where the project is hosted, by using:
string filePath = HttpContext.Current.Server.MapPath(".");
but i keep getting this exception:
DirectoryNotFoundException - "Could not find a part of the path C:\websites....
It seems like my iis express doesn't have permission to write files.
if so, how do i give it permission?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IIS Express 在当前登录的用户身份下运行。如果您尝试写入的文件夹具有某些特殊访问权限,请向当前用户提供访问权限。
File.Open(filePath, FileMode.Create) 只会创建文件,如果目录不存在,则会抛出“DirectoryNotFound”异常,这是预期的。因此,在创建文件之前,请确保该目录存在。也许你可以使用 Directory.CreateDirectory("directory path") API
IIS Express runs under current logged on user identity. If the folder you are trying to write has some special access, then provide acccess to current user.
File.Open(filePath, FileMode.Create) would create only files, if the directory does not exit, it throws 'DirectoryNotFound' exception and it is expected. So, before creating a file, make sure that directory exists. probably you can use Directory.CreateDirectory("directory path") API
您需要向 NETWORK SERVICE 帐户授予对您尝试写入的文件夹的写入权限。 MapPath 方法还采用虚拟目录根目录的相对 url:
You need to grant write permissions to the NETWORK SERVICE account to the folder you are trying to write. Also the MapPath method takes a relative url to the root of the virtual directory: