使用 SharpSVN 进行 SVN 存储库身份验证

发布于 2024-09-06 08:34:17 字数 67 浏览 6 评论 0原文

谁能告诉我如何使用 SharpSVN 库对存储库的用户(SVN 用户)进行身份验证。 该存储库只能由这些用户提交。 谢谢

Can any one tell me how to authenticate users(SVN users) for a repository using SharpSVN Library.
That repository should only be committed by those users.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彻夜缠绵 2024-09-13 08:34:17

使用 SVNClient 的 Authenticate 属性:

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

Use the Authenticate properties of SVNClient:

client.Authentication.Clear(); // Clear a previous authentication
client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user", "password");
梦明 2024-09-13 08:34:17
client.Authentication.ForceCredentials("user", "password");

对于那些不想破坏默认凭据的人(如果您在同一台计算机上运行 TortoiseSVN)。

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).

被翻牌 2024-09-13 08:34:17

您还可以通过向 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;
}

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;
}
苏辞 2024-09-13 08:34:17

就我而言,SVN 服务器运行的是 VisualSVN Server 3.5.3,并启用了集成 Windows 身份验证。使用 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 用户运行时,这会导致以下错误:

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

我修复了此问题通过仅允许basicdigest身份验证

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");

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文