Authentication 在SharpSvn.NET库中设置提交作者会引发SvnReprisitorIoException异常

Authentication 在SharpSvn.NET库中设置提交作者会引发SvnReprisitorIoException异常,authentication,tortoisesvn,commit,sharpsvn,author,Authentication,Tortoisesvn,Commit,Sharpsvn,Author,如果您有使用SharpSvn.NET库的经验,我可以利用您在SVN提交期间设置提交作者的专业知识。我已经尝试了一些方法,但是它们都抛出了一个svnReprisitoryOException,除非用户保存在龟甲vn中。但是,我希望根据情况使用不同的用户凭据。如果我保存了一个用户的默认凭据,则OttoiseSVN会在“设置”>“保存的数据”>“已验证的数据”中记住这些凭据,并能够使用该已验证用户作为提交作者提交文件。如果单击此处的“清除”,SharpSVN将不知道在提交过程中要对谁进行身份验证 假设

如果您有使用SharpSvn.NET库的经验,我可以利用您在SVN提交期间设置提交作者的专业知识。我已经尝试了一些方法,但是它们都抛出了一个svnReprisitoryOException,除非用户保存在龟甲vn中。但是,我希望根据情况使用不同的用户凭据。如果我保存了一个用户的默认凭据,则OttoiseSVN会在“设置”>“保存的数据”>“已验证的数据”中记住这些凭据,并能够使用该已验证用户作为提交作者提交文件。如果单击此处的“清除”,SharpSVN将不知道在提交过程中要对谁进行身份验证

假设您的类中有以下指令:使用SharpSvn; 使用SharpSvn.安全性;我正在使用免费版本的VisualSVN server for Windows。我有两个用户,一个名为“user1”,另一个密码为“pass1”,以便在下面失败的示例中保持简单

如何防止引发此异常并使用作者的不同用户提交(在提交日志中)

尝试#1:

    using (SvnClient client = new SvnClient())
    { 
        client.Authentication.Clear();  // Clear a previous authentication 
        client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user1", "pass1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }
    using (SvnClient client = new SvnClient())
    {
        client.SetProperty(("", "svn:author", "user1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }
            client.Authentication.Clear(); // Clear predefined handlers
            client.Authentication.UserNamePasswordHandlers
                += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
            {
                args.UserName = "user1";
                args.Password = "pass1";
            }; 

            client.Authentication.SslServerTrustHandlers​ +=
            delegate(object sender, SvnSslServerTrustEventArgs e)
            {
              e.AcceptedFailures = e.Failures;
              e.Save = true; // Save acceptance to authentication store
            };

            SvnCommitArgs ca = new SvnCommitArgs();
            ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
            bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
尝试#2:

    using (SvnClient client = new SvnClient())
    { 
        client.Authentication.Clear();  // Clear a previous authentication 
        client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user1", "pass1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }
    using (SvnClient client = new SvnClient())
    {
        client.SetProperty(("", "svn:author", "user1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }
            client.Authentication.Clear(); // Clear predefined handlers
            client.Authentication.UserNamePasswordHandlers
                += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
            {
                args.UserName = "user1";
                args.Password = "pass1";
            }; 

            client.Authentication.SslServerTrustHandlers​ +=
            delegate(object sender, SvnSslServerTrustEventArgs e)
            {
              e.AcceptedFailures = e.Failures;
              e.Save = true; // Save acceptance to authentication store
            };

            SvnCommitArgs ca = new SvnCommitArgs();
            ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
            bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
尝试#3:

    using (SvnClient client = new SvnClient())
    {
        client.Authentication.Clear(); // Clear predefined handlers
        client.Authentication.UserNamePasswordHandlers
            += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
        {
            args.UserName = "user1";
            args.Password = "pass1";
        }; 

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }

在以管理员身份运行应用程序时获得堆栈跟踪后,我能够使用框架捕获异常并接受不受信任的证书颁发者

*未处理的异常:SharpSvn.SvnRepositoryIOException:提交失败(详细信息如下):=>SharpSvn.SvnRepositoryIOException:无法连接到URL'处的存储库https://mycomputer/svn/demo_repo/demo_project/trunk/file.txt“-->SharpSvn.SvnRepositoryIOException:选项“”:服务器证书验证失败:颁发者不受信任(https://mycomputer) ---内部异常堆栈跟踪的结束--- ---内部异常堆栈跟踪的结束--- 位于SharpSvn.SvnClientArgs.HandleResult(SvnClientContext客户端,SvnException错误,对象目标) 在SharpSvn.SvnClientArgs.HandleResult(SvnClientContext客户端,svn_error_t*error,对象目标) *

新代码:

    using (SvnClient client = new SvnClient())
    { 
        client.Authentication.Clear();  // Clear a previous authentication 
        client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user1", "pass1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }
    using (SvnClient client = new SvnClient())
    {
        client.SetProperty(("", "svn:author", "user1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }
            client.Authentication.Clear(); // Clear predefined handlers
            client.Authentication.UserNamePasswordHandlers
                += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
            {
                args.UserName = "user1";
                args.Password = "pass1";
            }; 

            client.Authentication.SslServerTrustHandlers​ +=
            delegate(object sender, SvnSslServerTrustEventArgs e)
            {
              e.AcceptedFailures = e.Failures;
              e.Save = true; // Save acceptance to authentication store
            };

            SvnCommitArgs ca = new SvnCommitArgs();
            ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
            bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);