问题描述
如果你有使用SharpSvn .NET库的经验,我可以用你的专业知识在SVN中设置提交作者提交。我已经尝试了一些东西,但他们都抛出SvnRepisitoryIOException除非用户保存在TortoiseSVN的。不过,我想请根据情况不同的用户凭据。如果我保存了用户的默认凭据,TortoiseSVN会记住他们在设置>保存数据>认证的数据,以及使用能够提交的文件认证的用户作为提交者。如果你点击清除在这里,SharpSVN不会知道是谁在给提交身份验证。
假设你在你的类这些指令:使用SharpSvn;
使用SharpSvn.Security;我使用VisualSVN服务器for Windows的免费版本。我有两个用户,一个被命名的PASS1,用户1和密码,让事情变得简单在下面的例子失败。
我如何prevent从此异常被抛出,并承诺使用不同的用户为作者(在我的日志提交)?
尝试#1:
使用(SvnClient客户端=新SvnClient())
{
client.Authentication.Clear(); //清除一个previous认证
client.Authentication.DefaultCredentials =新System.Net.NetworkCredential(用户1,PASS1); SvnCommitArgs CA =新SvnCommitArgs();
ca.LogMessage =在创建了svn日志消息+ DateTime.Now.ToString();
布尔行动= client.Commit(@C:\\ demo_repo \\ demo_project \\干线\\ file.txt的,CA);
}
尝试#2:
使用(SvnClient客户端=新SvnClient())
{
client.SetProperty((,SVN:作者,USER1); SvnCommitArgs CA =新SvnCommitArgs();
ca.LogMessage =在创建了svn日志消息+ DateTime.Now.ToString();
布尔行动= client.Commit(@C:\\ demo_repo \\ demo_project \\干线\\ file.txt的,CA);
}
尝试3:
使用(SvnClient客户端=新SvnClient())
{
client.Authentication.Clear(); //清除predefined处理程序
client.Authentication.UserNamePasswordHandlers
+ =委托(obj对象,SharpSvn.Security.SvnUserNamePasswordEventArgs参数)
{
args.UserName =USER1;
args.Password =PASS1;
}; SvnCommitArgs CA =新SvnCommitArgs();
ca.LogMessage =在创建了svn日志消息+ DateTime.Now.ToString();
布尔行动= client.Commit(@C:\\ demo_repo \\ demo_project \\干线\\ file.txt的,CA);
}
让运行的应用程序作为管理员时,堆栈跟踪后,我能够用框架来捕获异常,并接受非受信任的证书颁发者。
*未处理的异常:SharpSvn.SvnRepositoryIOException:提交失败(细节如下):===> SharpSvn.SvnRepositoryIOException:无法在URL的https连接到存储库:// MYCOMPUTER / SVN / demo_repo / demo_project /主干/文件.TXT' - > SharpSvn.SvnRepositoryIOException:选项'':服务器证书验证失败:发行人不被信任(https://开头MYCOMPUTER)
---内部异常堆栈跟踪的结尾---
---内部异常堆栈跟踪的结尾---
在SharpSvn.SvnClientArgs.HandleResult(SvnClientContext客户端,SvnException错误,对象目标)
在SharpSvn.SvnClientArgs.HandleResult(SvnClientContext客户端,svn_error_t *错误,对象目标)
..... *
新建code:
client.Authentication.Clear(); //清除predefined处理程序
client.Authentication.UserNamePasswordHandlers
+ =委托(obj对象,SharpSvn.Security.SvnUserNamePasswordEventArgs参数)
{
args.UserName =USER1;
args.Password =PASS1;
}; client.Authentication.SslServerTrustHandlers + =
委托(对象发件人,SvnSslServerTrustEventArgs E)
{
e.AcceptedFailures = e.Failures;
e.Save = TRUE; //保存验收认证店
}; SvnCommitArgs CA =新SvnCommitArgs();
ca.LogMessage =在创建了svn日志消息+ DateTime.Now.ToString();
布尔行动= client.Commit(@C:\\ demo_repo \\ demo_project \\干线\\ file.txt的,CA);
If you have experience with using the SharpSvn .NET library, I could use your expertise in setting the commit author during an SVN commit. I've tried a few things, but they all throw an SvnRepisitoryIOException unless the user is saved in TortoiseSVN. However, I want to use different user credentials depending on the situation. If I've saved a user's default credentials, TortoiseSVN remembers them in Settings > Saved Data > Authenticated Data, and is able to commit a file using that authenticated user as the commit author. If you click "Clear" here, SharpSVN won't know who to authenticate during a commit.
Assume you have these directives in your class: using SharpSvn;using SharpSvn.Security; I'm using the free version of VisualSVN server for Windows. And I have two users, one being named "user1" and password of "pass1" to keep things simple in the examples below that failed.
How can I prevent this exception from being thrown and commit using different users for the author (in my log of the commit)?
Attempt #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);
}
Attempt #2:
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);
}
Attempt #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);
}
After getting the stack trace when running the application as an administrator, I was able to catch the exception using the framework and accept the non trusted certificate issuer.
*Unhandled Exception: SharpSvn.SvnRepositoryIOException: Commit Failed (details follow): ===> SharpSvn.SvnRepositoryIOException: Unable to connect to a repository at URL 'https://mycomputer/svn/demo_repo/demo_project/trunk/file.txt' --> SharpSvn.SvnRepositoryIOException: OPTIONS of '': Server certificate verification failed: issuer is not trusted (https://mycomputer) --- End of inner exception stack trace --- --- End of inner exception stack trace --- at SharpSvn.SvnClientArgs.HandleResult(SvnClientContext client, SvnException error, Object targets) at SharpSvn.SvnClientArgs.HandleResult(SvnClientContext client, svn_error_t* error, Object targets) .....*
New Code:
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);
这篇关于在设置.NET SharpSvn库提交笔者抛出异常SvnRepisitoryIOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!