1

在将我们的身份验证机制更改为Windows身份验证后,我在服务调用期间收到异常。由于无法诊断,我有点失去意志。这似乎是一个非常普遍的错误埋在MVC身份验证的深处。如何调试此Windows验证问题?

的错误信息是:

Response status code does not indicate success: 500 (Internal Server Error) 

我的调用堆栈是这样的(我的方法调用删除隐私):

System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +137 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +65 
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97 
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +17 
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +48 
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50 
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225 
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225 
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10 
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +48 
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26 
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100 
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29 
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +137 

这是我的web.config:

<authentication mode="Windows" /> 
<authorization> 
    <deny users="?" /> 
</authorization> 

这里是我使用的代码:

HttpClientHandler handler = new HttpClientHandler() 
{ 
    UseDefaultCredentials = true 
}; 

HttpClient client = new HttpClient(handler); 
var result = await client.GetAsync(uri); 
result.EnsureSuccessStatusCode(); 

EnsureSuccessStatusCode因为通话返回500而引发。

它没有打我的任何代码。我在另一端的入口处有断点。那么是什么原因造成的呢?我如何调试并获取足够的信息来修复它?我觉得必须有办法获得更多我不知道的信息?

如果有人能告诉我如何诊断问题,我不一定需要解决方案吗?

+0

当您针对Visual Studio内置的Web主机运行时,您是否遇到500错误,或者您是否在针对完全安装的IIS版本运行时看到这些错误? –

+0

使用内置的Web主机运行。在我编写的一个原型应用程序中,所有事情都以这种方式工作,并且令人遗憾地转向完整的IIS不是一种选择,因为它是我们在公司工作的方式 – Jon

回答

0

这里是this答案的解决方案:

if (!result.IsSuccessStatusCode) 
{ 
    string msg = result.Content.ReadAsStringAsync().Result; 
    throw new Exception(msg); 
} 

result.EnsureSuccessStatusCode(); 

很显然,我不会推荐这对生产代码(或作为一种使用异步代码),但是这将让你在调试确切的错误信息你服务电话。

事实上,在实际获取错误消息的五分钟内调试错误并进行了修复。