What is the correct way to call unmanaged code such as a COM API through .Net interop from a code that is being executed in a partially trusted environment?
While developing an ASP.Net WebPart for Microsoft SharePoint I had to communicate with another system through its COM API. I solved this issue temporarily by changing SharePoint's permissions to full. Later I refined this by implementing custom security on top of the minimal settings which gives SharePoint UnmanagedCode permission but this isn't that big of an improvement as unmanaged code can skip the rest of the CAS.
From what I have gathered I probably need a fully trusted assembly which allows partially trusted callers and acts as a layer between the managed and unmanaged domains. Also I'd imagine there is a need for some extra settings which allow the partially trusted code call fully trusted code without the fully trusted code suffering from the permissions of the partially trusted code.
So what is the correct way and how to implement it in practice?