【发布时间】:2018-12-21 20:21:53
【问题描述】:
我有一个简单的 OWIN 自托管应用程序,它带有一个扩展 ApiController 的控制器。问题是,当我向控制器发送一个没有数据的 POST 请求(该方法没有参数)时,它返回:
需要长度
然后应用程序因未处理的ObjectDisposedException 而崩溃(下面是完整的堆栈跟踪)。如果 POST 请求包含数据,则一切正常。
我通过使用这种简单的方法进行复制,从方程式中删除了所有控制器逻辑:
[HttpPost]
public void MyMethod()
{
return;
}
因此我猜这与路由有关?但我的路线只设置为默认:
config.Routes.MapHttpRoute("My Service", "{controller}/{action}/{id}", new { id = RouteParameter.Optional });
为什么我的应用程序会以这种方式运行?
发送请求我使用curl:
curl --request POST http://localhost/mycontroller/mymethod
堆栈跟踪:
未处理的异常:System.ObjectDisposedException:无法访问 处置的对象。对象名称:“System.Net.HttpListenerResponse”。在 System.Net.HttpListenerResponse.set_StatusCode(System.Int32 值) [0x00016] 在 :0 中 Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerResponse.End () [0x0001c] 在 :0 处 Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerContext.End () [0x00010] 在 :0 处 Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerContext.End (System.Exception ex) [0x0001e] in :0 在 Microsoft.Owin.Host.HttpListener.OwinHttpListener+d__5.MoveNext () [0x001f9] 在 :0 --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] 在 :0 处 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task 任务) [0x0004e] in :0 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task 任务) [0x0002e] in :0 在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task 任务) [0x0000b] in :0 在 System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] 在 :0 在 Microsoft.Owin.Host.HttpListener.OwinHttpListener+d__0.MoveNext () [0x00202] 在 :0 --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] 在 :0 处 System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__1 (System.Object 状态)[0x00000] 在 :0 在 System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object 状态) [0x0000e] in :0 在 System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调,System.Object 状态, System.Boolean preserveSyncCtx) [0x0008d] in :0 在 System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调,System.Object 状态, System.Boolean preserveSyncCtx) [0x00000] 在 :0 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x0002a] 在 :0 处 System.Threading.ThreadPoolWorkQueue.Dispatch() [0x00096] in :0 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [0x00000] 在 :0
【问题讨论】:
标签: c# asp.net-web-api owin