此 answer 中提供的以下代码有一段时间运行良好,但现在它再次抛出 Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: 'TF30063: You are not authorized to access https://{mysite}.visualstudio.com/.'。 p>
var credentials = new VssClientCredentials();
credentials.PromptType = CredentialPromptType.PromptIfNeeded;
var teamProjects = new TfsTeamProjectCollection(tfsCollectionUri, credentials);
teamProjects.EnsureAuthenticated(); // exception thrown
问我该如何解决这个问题?
更新 够奇怪的,
- 在执行
teamProjects.EnsureAuthenticated();
之前,调试器为credentials.PromptType
读取PromptIfNeeded
。 - 在抛出异常且调试器停止执行后,它会读取
DoNotPrompt
以获取credentials.PromptType
。
观察 上面的代码在控制台应用程序中运行良好,但在 Windows 窗体应用程序中无法运行(即抛出异常)。
Q1 如何让上述代码在 Windows 窗体应用程序中运行?
最佳答案
如果您在 Task
(即一个单独的线程)中执行上面的代码,它就可以正常工作。如果凭据在注册表中的位置不存在或过时(请参阅此 answer ),将打开一个窗口,您可以对自己进行身份验证。
谁能解释一下为什么会这样?
关于c# - TF30063 : You are not authorized . .. 编程访问不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47637033/