首页 > 解决方案 > 尝试在本地 IIS 中启动时获取 Microsoft.VisualStudio.Services.Common.VssUnauthorizedException:'VS30063

问题描述

我正在运行一个简单的 Web 应用程序,在 VisualStudio.Services.Common 旁边测试 TeamFoundation.Services.Client 并通过 IIS Express 启动应用程序没有问题,但是当我尝试使用本地 IIS 执行相同操作时,我收到此错误:

Microsoft.VisualStudio.Services.Common.VssUnauthorizedException: 'VS30063: You are not authorized to access http://mytfs:8080.

This exception was originally thrown at this call stack:
    Microsoft.VisualStudio.Services.Common.VssHttpMessageHandler.SendAsync(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
    Microsoft.VisualStudio.Services.Common.VssHttpRetryMessageHandler.SendAsync(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    System.Net.Http.HttpClient.FinishSendAsyncBuffered(System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>, System.Net.Http.HttpRequestMessage, System.Threading.CancellationTokenSource, bool)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    ...
    [Call Stack Truncated]

我不明白问题是什么。

这是我试图启动它的调试配置文件: 在此处输入图像描述

这是我得到错误的代码:

internal const string vstsCollectioUrl = "http://myTFS:8080/tfs/MyCollection"; 

//Prompt user for credential
VssConnection connection = new VssConnection(new Uri(vstsCollectioUrl), new VssAadCredential("{user}", "{password}"));

//create http client and query for resutls
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();

标签: asp.net-core.net-coretfsazure-devopsazure-active-directory

解决方案


默认情况下,VssAadCredential该类采用运行该工具的人员的凭据,并且不遵守.net core项目中实际的用户名和密码参数,类似于此票证。所以不能像这样使用 Azure Active Directory Authentication ,也不建议在SOAP 服务中对 REST 服务使用 AAD Authentication

作为一种解决方法,您可以尝试 Windows 身份验证:

VssConnection connection = new VssConnection(new Uri("http://instanceName:8080/tfs/OrgName/"), new WindowsCredential(new NetworkCredential("xxx", "xxx")));

推荐阅读