ISAPI 或 ASP.NET 中的内存映射文件 - FileNotFoundException
我正在 .NET4 中编写一个程序,它以这种方式生成内存映射文件: MemoryMappedFile.CreateNew("TEST", int.MaxValue))
我创建了 ISAPI 模块,该模块安装在 IIS7 上,该模块会读取 MemoryMappedFile 但不幸的是它不起作用,我收到错误: System.IO.FileNotFoundException:无法找到指定的文件。
该程序与 IIS7 位于同一台 PC 上,IIS 在同一台 PC 上运行用户作为我的程序。如果我将 ISAPI 中的代码放到另一个程序中,我可以毫无问题地读取 MemoryMappedFile。
当我在 ASP.NET 中使用我的代码(读取 MemoryMappedFile)时,也会出现同样的问题。看起来 IIS 阻止了系统应用程序和 ISAPI 或 ASP.NET 之间的 MemoryMappedFile。
怎么解决呢? MemoryMappedFile 对我很重要。
谢谢
I am writing a program in .NET4 which generates Memory Mapped Files in this way: MemoryMappedFile.CreateNew("TEST", int.MaxValue))
I have created ISAPI module which is instaled on IIS7, this module would read MemoryMappedFile but unfortunately it does not work, I get an error: System.IO.FileNotFoundException: Unable to find the specified file.
The Program is on the same PC as IIS7, IIS works on the same user as my program. If I put my code from ISAPI to another program and I can read MemoryMappedFile without any problems.
The same problem occours when I use my code (which read MemoryMappedFile) in ASP.NET. It looks like IIS blocked MemoryMappedFile between system aplication and ISAPI or ASP.NET.
How to solve it? MemoryMappedFile is important to me.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于无法查看相关代码,我可以建议一些调查途径:
您确定在尝试通过 ISAPI 扩展访问该句柄时该句柄仍然存在吗?如果创建该文件的进程不再运行,它将被垃圾收集并且不会被发现。您可以使用 Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653) 搜索内存映射文件(它将显示为“section”类型的句柄)。
如果这不起作用,请尝试让您的 ISAPI 扩展分配其自己的内存映射文件,并查看它是否可以读取自己的文件。
尝试为内存映射文件分配较低的容量 - 将容量设置为 4 GB,如您的示例所示,这可能是问题所在。
Without being able to look at the code in question, I can suggest some avenues of investigation:
Are you certain that the handle still exists at the time you are attempting to access it via the ISAPI extension? If the process that created the file is no longer running, it will be garbage-collected and will not be found. You can use Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653) to search for your memory-mapped file (it will appear as a handle of type "section").
If that doesn't work, try having your ISAPI extension allocate its own memory-mapped file and see if it can read it's own files.
Try allocating a lower capacity to the memory mapped file - setting the capacity to 4 GB as in your example might be the issue.
该问题可能是命名空间问题,这是尝试在两个会话之间按名称共享同一内存映射文件的结果。由于 IIS 作为服务运行,因此它在“会话 0”中运行,而其他用户应用程序将在不同的交互式会话中运行。每个会话都有自己的命名空间,用于命名资源(如内存映射文件)。
尝试在文件名前添加“Global\”,例如:
The problem could be a namespace issue, the result of trying to share the same memory-mapped file by name between two sessions. As IIS is running as a service, it runs in 'session 0', while other user applications will run in a different interactive session. Each session has its own namespace for named resources (like memory-mapped files).
Try prepending "Global\" to the filename, like: