我在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. }
如果我删除第4行和第5行,这段代码没有任何问题.我假设它是以某种方式使用我保存的凭据在本地从TortoiseSVN.但是,我想在服务器环境中运行,我需要特别传入一个用户名/密码.但是,一旦我尝试放入登录凭据,我在第10行得到以下错误:
- SharpSvn.SvnRepositoryIOException was unhandled
- Message: Unable to connect to a repository at URL
我在这里做错了什么?我已经验证了我尝试使用的用户名/密码做工作.
解决方法
我找到答案…添加第5行之后:
- client.Authentication.SslServerTrustHandlers += delegate(object sender,SvnSslServerTrustEventArgs e) {
- e.AcceptedFailures = e.Failures;
- e.Save = true; // Save acceptance to authentication store
- };