【问题标题】:SVN Repository Authentication using SharpSVN使用 SharpSVN 的 SVN 存储库身份验证
【发布时间】:2011-03-07 04:15:07
【问题描述】:

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

【问题讨论】:

    标签: svn authentication sharpsvn


    【解决方案1】:

    使用SVNClient的Authenticate属性:

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

    【讨论】:

    • 这对我不起作用,是否有一些先决条件?
    • 仅限 SharpSVN 库。您确定您的用户名和密码吗?
    【解决方案2】:
    client.Authentication.ForceCredentials("user", "password");
    

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

    【讨论】:

    • 有了这个我可以进行身份​​验证,但它会更改我在 TortoiseSVN 上的默认凭据。
    【解决方案3】:

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

    【讨论】:

    • 刚刚提到:订阅事件后不要调用'client.authentication.clear()',否则它不会触发。
    • @SanBen 谢谢谢谢谢谢!我今天在这一点上挂了几个小时。
    【解决方案4】:

    在我的例子中,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' 的存储库

    我通过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");
    

    【讨论】:

      猜你喜欢
      • 2012-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      相关资源
      最近更新 更多