Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVN Repository Authentication with SharpSVN - Credentials not working

Tags:

c#

sharpsvn

I have the following code in C#:

1.  public static void Main(string[] args) {
2.  Uri repository = new Uri("https://svnserver:port/svn/Src/trunk");
3.  using (SvnClient client = new SvnClient()) {                
4.    client.Authentication.Clear();
5.    client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user", "pass");
6.
7.    System.Collections.ObjectModel.Collection<SvnLogEventArgs> logEntries;
8.    SvnLogArgs logArgs = new SvnLogArgs();
9.    logArgs.Limit = 1;
10.   client.GetLog(repository, logArgs, out logEntries);
11.   }
12. }

If I remove lines 4 and 5, this code works without any issue. I'm assuming it's somehow using my saved credentials locally from TortoiseSVN. However, I want to run this in a server environment and I need to specifically pass in a username/password. However, as soon as I attempt to put in the login credentials I get the following error on line 10:

SharpSvn.SvnRepositoryIOException was unhandled
Message: Unable to connect to a repository at URL

What am I doing wrong here? I have verified that the username/password I'm attempting to use do work.

like image 283
Adam Levitt Avatar asked Dec 14 '12 23:12

Adam Levitt


1 Answers

I found the answer... add this after line 5:

client.Authentication.SslServerTrustHandlers += delegate(object sender, SvnSslServerTrustEventArgs e) {
                    e.AcceptedFailures = e.Failures;
                    e.Save = true; // Save acceptance to authentication store
                };
like image 115
Adam Levitt Avatar answered Sep 22 '22 13:09

Adam Levitt