Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...
 


Wednesday, July 19

.NET Remoting - setting credentials

When a client calls a secure remote object that is hosted within IIS (ASP.NET worker process - Windows Authentication), you must specify explicit credentials to be authenticated. You can also choose to use the credentials (DefaultCredentials) of the process hosting the remote object proxy. If no credentials are passed to the remote object, you will be bothered with the HTTP 401 error (Access denied).

This is an easy way to set your explicit credentials programmatically ...

object proxy =  Activator.GetObject(resourceType, endPoint);

 

ICredentials networkCredentials = new NetworkCredential(userName, password, domain);

IDictionary dictionary = ChannelServices.GetChannelSinkProperties(proxy);

dictionary["credentials"] = networkCredentials;


Your proxy is now ready to invoke the necessary secured methods on the remote object. Setting your credentials programmatically can be convenient for quick testing purposes. Most of the time you will solely rely on configuration settings, but this can be a tedious task from time to time.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home