Search code examples
c#sharpsvn

SharpSVN ForceCredentials overwrites authentication cache


SVN, like every mature tool used for lots of different purposes, is complex. SharpSVN tries to expose all SVN features programmatically, so it is complex, too. I just tried to authorize a tool with a given username/password on a machine where TortioseSVN is used for other purposes on the same SVN server (realm).

var client = new SvnClient();
client.Authentication.ForceCredentials("userName", "password");

Unfortunately, this replaced the existing credentials cached by TortioseSVN to these used by the tool. Is there a simple way to avoid overwriting the authentication cache and also ignore what is in there?


Solution

  • Although the possibilities are endless by subscribing to the UserNameHandlers and UserNamePasswordHandlers events of the client.Authentication property, the simplest solution seems to be this:

    var client = new SvnClient();
    client.Authentication.Clear();
    client.Authentication.DefaultCredentials = new NetworkCredential("userName", "password");