2010-06-23 57 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");