iis-express 文件访问权限

发布于 2024-10-30 14:31:28 字数 328 浏览 8 评论 0原文

我正在运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三人与歌 2024-11-06 14:31:28
  1. IIS Express 在当前登录的用户身份下运行。如果您尝试写入的文件夹具有某些特殊访问权限,请向当前用户提供访问权限。

  2. File.Open(filePath, FileMode.Create) 只会创建文件,如果目录不存在,则会抛出“DirectoryNotFound”异常,这是预期的。因此,在创建文件之前,请确保该目录存在。也许你可以使用 Directory.CreateDirectory("directory path") API

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

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

浴红衣 2024-11-06 14:31:28

您需要向 NETWORK SERVICE 帐户授予对您尝试写入的文件夹的写入权限。 MapPath 方法还采用虚拟目录根目录的相对 url:

var path = HttpContext.Current.Server.MapPath("~/");

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:

var path = HttpContext.Current.Server.MapPath("~/");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文