2010-06-23 61 views

回答

45

使用的SVNClient的身份验证属性:

client.Authentication.Clear(); // Clear a previous authentication 
client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user", "password"); 
+1

应该标记为最佳答案。为我工作,谢谢! – jocull 2011-05-14 16:50:53

+0

是的,我也为我工作,谢谢伯特朗:) – picnic4u 2012-12-06 10:36:02

+1

这不适合我,是否有一些先决条件呢? – 2012-12-14 23:49:25

9

你也可以通过添加一个事件处理SslServerTrustHandlers像这样覆盖SSL证书错误:

SVN_Conn.Authentication.SslServerTrustHandlers += new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(SVN_SSL_Override); 

static void SVN_SSL_Override(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e) 
{ 
    e.AcceptedFailures = e.Failures; 
    e.Save = true; 
} 
+4

只是为了提到它:在订阅事件后不要调用'client.authentication.clear()',否则它不会触发。 – SanBen 2012-05-09 12:53:41

14
client.Authentication.ForceCredentials("user", "password"); 

对于那些你不想吹掉你的默认凭证(如果你在同一台机器上运行TortoiseSVN)。

2

就我而言,SVN服务器运行启用集成Windows身份验证的VisualSVN Server 3.5.3。使用SharpSvn 1.9004.3879.127,SVN客户端尝试甚至使用Windows身份验证时,我有一个用户名和密码进行配置的:

client = new SvnClient(); 
client.Authentication.Clear(); //Prevents saving/loading config to/from disk 
client.Authentication.DefaultCredentials = new NetworkCredential("username", "password"); 

这导致以下错误,当应用程序代码是由没一个Windows用户运行'T可以访问存储库:

SvnRepositoryIOException:无法在URL连接到存储库' https://mysvnserver/svn/reponame

我通过only allowing basic and digest authentication解决了这个问题:

client = new SvnClient(); 
client.Configuration.SetOption("servers", "global", "http-auth-types", "basic;digest"); 
client.Authentication.Clear(); // Prevents saving/loading config to/from disk 
client.Authentication.DefaultCredentials = new NetworkCredential("username", "password");