I have an application with the AppDomain server that accepts calls from individual AppDomains (which are host plugins developed by other people and not trustworthy).
From the AppDomain server, I need to know which “plug-in” (AppDomain) actually makes the call so that I can make sure that this plug-in has access to the resource.
I can simply pass the credentials to a call to the remote call method, but I am concerned that the cunning programmer of Plug-in A may change the code so that it appears from Plug-in B.
I considered creating my own implementation of ObjRef in a Server application, believing that "ChannelInfo.ChannelData" might contain information about the client plug-in making the call, and implemented the following code:
public int DomainId
{
get
{
int domainId = -1;
for (int i = 0; i < ChannelInfo.ChannelData.Length; i++)
{
object o = ChannelInfo.ChannelData[i];
if (o.ToString() == "System.Runtime.Remoting.Channels.CrossAppDomainData")
{
System.Reflection.BindingFlags flags =
System.Reflection.BindingFlags.GetProperty
| System.Reflection.BindingFlags.Instance
| System.Reflection.BindingFlags.NonPublic;
domainId = (int)o.GetType().GetProperty("DomainID", flags).GetValue(o, null);
}
}
return domainId;
}
}
But the DomainId obtained from this is the same as the AppDomain.CurrentDomain.Id servers when I really need the AppDomain Id of the client (caller)
It feels like it's too complicated :-)
Any ideas?
source
share