Opening a Memory Mapped File causes FileNotFoundException when deployed in IIS

后端 未结 3 1830
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 06:21

Following the code example from this website, I created a windows console application that creates a mapped memory file:

        using (var file = MemoryMapp         


        
3条回答
  •  醉话见心
    2021-01-18 06:45

    Add "Global\\" prefix to the mapName. That is the only way it worked for me. When we try to access shared memory created in the first process it runs in a different security context and shared memory objects are not visible unless they are created in the global namespace.

    This is the code that worked for me. I used CreateOrOpen in a WinForm application and I used OpenExisting in an IIS process:

    mSec = new MemoryMappedFileSecurity();
    mSec.AddAccessRule(new AccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MemoryMappedFileRights.FullControl, AccessControlType.Allow));
    
    mmf = MemoryMappedFile.CreateOrOpen("Global\\\MmfName", 100, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, mSec, HandleInheritability.Inheritable);
    
    mmf = MemoryMappedFile.OpenExisting("Global\\\MmfName");
    

提交回复
热议问题