IIS7 - 从应用程序池读取文件
编辑:我让这变得比它需要的更加混乱。忘记这是一个 Silverlight 客户端。我有一个托管在 IIS 中的 WCF 服务,需要访问本地文件系统上的文件。这项服务的使用者将是 Silverlight,但我认为这并不重要,应该将其排除在外。
我有一个 Silverlight 应用程序,我在其中托管服务。在此服务中,我想读取 C 驱动器根目录中的文本文件(仅用于测试)。我收到一个异常,提示无法找到该文件。我认为这是一个权限问题,但我无法弄清楚。
我的应用程序池身份设置为 NetworkService。我将 .NET 信任级别设置为完全(内部)。我什至向 NetworkService 用户授予对我尝试读取的文本文件的读取权限。
该服务需要有权访问文件系统。执行此操作的正确方法是什么?
谢谢,
-斯科特
EDIT: I made this more confusing than it needed to be. Forget that this is a Silverlight client. I have a WCF service hosted in IIS that needs to have access to a file on the local file system. A consumer of this service will be Silverlight, but I don't think that's important and should have left that out.
I have a Silverlight application where I host a service. Within this service, I want to read a text file in the root of the C drive (just for testing). I'm getting an exception thrown that the file could not be found. I think this is a permissions issue, but I can't figure it out.
I have my app pool Identity set to NetworkService. I have the .NET Trust Level set to Full (Internal). I have even gone as far as granting read permissions to the NetworkService user on the text file I am trying to read.
The service needs to have access to the file system. What is the proper way to do this?
Thanks,
-Scott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,从方程式中剔除现实生活中不会出现的东西。在实际应用程序中,您不会从 C:\ 读取数据。所以值得考虑一下你将从哪里阅读。
我建议您的文件位于网站的
App_Data
文件夹中。因此,请尝试将文件放在那里,然后从服务访问它。您可以使用以下方法解析 App_Data 物理文件:First of all take out of the equation things that won't be in the equation in real life. In the real application you aren't going to be reading from C:\. So its worth thinking about where you will be reading from.
I propose that your file will be in the
App_Data
folder of the website. So try putting a file there and then accessing it from the service. You can resolve the App_Data physical file with: