SVN Repository Authentication using SharpSVN

怎甘沉沦 提交于 2019-11-28 08:07:06

Use the Authenticate properties of SVNClient:

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

For those of you who don't want to blow away your default credentials (if you're running TortoiseSVN on the same machine).

jocull

You can also override SSL certificate errors by adding an event handler to SslServerTrustHandlers like this:

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;
}
Sam

In my case, the SVN server was running VisualSVN Server 3.5.3 with Integrated Windows Authentication enabled. Using SharpSvn 1.9004.3879.127, the SVN client tried to use Windows authentication even when I configured it with a username and password:

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

This resulted in the following error when the application code was run by a Windows user that didn't have access to the repository:

SvnRepositoryIOException: Unable to connect to a repository at URL 'https://mysvnserver/svn/reponame'

I fixed this by 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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!