TF30063:您无权...编程访问不起作用 [英] TF30063: You are not authorized ... programmatic access not working
问题描述
此 answer 中提供的以下代码在一段时间内效果很好,但现在抛出 Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException:'TF30063:您无权再次访问https://{mysite} .visualstudio.com/..
The code below provided in this answer did work well for a while but now its throwing Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: 'TF30063: You are not authorized to access https://{mysite}.visualstudio.com/.' again.
var credentials = new VssClientCredentials();
credentials.PromptType = CredentialPromptType.PromptIfNeeded;
var teamProjects = new TfsTeamProjectCollection(tfsCollectionUri, credentials);
teamProjects.EnsureAuthenticated(); // exception thrown
Q 如何解决此问题?
更新足够奇怪
- 在执行
teamProjects.EnsureAuthenticated();
之前,调试器为credentials.PromptType
读取PromptIfNeeded
. - 引发异常并且调试器停止执行之后,它会读取
DoNotPrompt
作为credentials.PromptType
.
- before executing
teamProjects.EnsureAuthenticated();
the debugger readsPromptIfNeeded
forcredentials.PromptType
. - after the exception has been thrown and the debugger has stopped the execution, it reads
DoNotPrompt
forcredentials.PromptType
.
观察 上面的代码在控制台应用程序中可以很好地运行,但是在Windows窗体应用程序中则无法工作(即,它引发异常).
Observation The above code works perfectly well in a console application but fails to work in a windows forms application (i.e. it throws an exception).
第1季度如何在Windows窗体应用程序中使以上代码工作?
Q1 How can I make the above code work in a windows forms application?
推荐答案
如果您在Task
(即一个单独的线程)中执行上述代码,那么它就可以正常工作.如果凭据在注册表中的位置不存在或过时(请参阅此 answer ),则会打开一个窗口,您可以进行身份验证你自己.
If you execute the code above within a Task
(i.e. a separate thread) it just works. If the credentials are not present or stale at the location in the registry (see this answer) a window opens and you can authenticate yourself.
任何人都可以解释为什么这样做有效吗?
Can anyone explain why this works?
这篇关于TF30063:您无权...编程访问不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!