This is my first blog, so jumping straight to the point. One intresting thing that I wanted to share for which I have not seen much documentation but people spending long hours figuring this out is how to pass credentials in .net Remoting.
Basically there would be two kinds of scenarios:
1. Passing default credentials:
i.e if a user wants to pass the windows credentials of the process along with the remoting request.In this scenario all you want to do is set the useDefaultCredentials property on the HttpChannel to true either programmatically:
channel = new HttpClientChannel(ChannelProps, ClientBinFormatter);
or through configuration file:
<channel ref="http" useDefaultCredentials="true" />
2. Passing custom Credentials:
If you want to specify the username, password at runtime and want to pass it with the remoting request. This has been different with .net 1.0 and .net 1.1.
.net 1.0 : All you want to do is set the credentials property on your HttpChannel and all remoting requests through this channel sink will use the specified credentials.
nICredential credObj = new NetworkCredential(userName,password,domain);
Properties["credentials"] = credObj;
HttpChannel hc = new HttpChannel(channelProperties,…, .... );
nobject obj = Activator.GetObject (type, url);
The catch with setting credentials on each proxy is that since Client activated objects sends a network request during 'new' or GetObject call, the credentials are already passed before you have your proxy. So to get around this problem if you want to pass custom credentials for CAO objects then we get the proxy to internal remoting object that is responsible for creating object on the server and set the credentials on that first.
Set credentials on ChannelSink of this internal proxy
2. Now when we register and create the CAO on the client, the 'new' call will use the credentials set on RemoteActivationService.rem proxy.
3. Get the Channelsink of the CAO proxy
4. Set Credentials on the CAO proxy