How do I marshall calls that use classes out of my control between two .NET processes?
I have the following scenario. My C# code will be executing in two processes - one process will be the IIS process running under "local service" account, the other will be running under an account with more privileges. Both processes will run C# code, .NET version will be at least 3.5.
The part under IIS contains a set of classes derived from System.Web.IHttpHandler
and each class implements IHttpHandler.ProcessRequest()
method that accepts System.Web.HttpContext
parameter.
I can't do anything useful from IIS part - I need filesystem access, DCOM server activation, other things "local service" can't do by default. So I'd like to somehow forward those ProcessRequest()
calls to the part running under开发者_如何转开发 the user with more privileges. I need to forward the object to another process, wait for the call to complete, then the other process will have changed the object and I want to get those changes on the caller process side - so that it looks like it's just one process.
I thought of WCF but I'm not sure it will manage to deal with marshalling HttpContext
between processes. AFAIK (might be wrong) it's necessary for a type to be marked with System.Runtime.Serialization.DataContractAttribute
([DataContract]
) in order to be marshalled, but HttpContext
is marked with this attribute.
Can I marshall HttpContext
through WCF to another process and back so that changes made by the callee are visible to the caller? What better options are there?
I would configure a separate application pool in IIS, running under a dedicated account with the needed privileges granted, and then configure your code to execute in this application pool. Then you no longer need to do this complicated process. Also, in your code you could simply impersonate the user with more privileges to execute your special code sequence.
Dan suggestion is probably simplest if your environment supports that security model.
If not, then is there something particular in your usage of HttpContext that you need to marshall the object itself? I would probably just create a serializable message or data transfer object based on the information contained within HttpContext and send that object to my remote process. The remote process would send a response object back, which I could then use to complete any steps handled on the IIS side.
精彩评论