【发布时间】:2018-07-25 06:10:52
【问题描述】:
我得到了很多类似下面的日志,有人知道这件事的根本原因吗?这是否与以下代码有关:
// Gets the client IP when hosted in IIS, where HttpContext.Current is not null.
if (httpRequest != null)
return httpRequest.UserHostAddress;
// Gets the client IP when hosted in Owin, where there is no HttpContext.Current by default.
if (!request.Properties.ContainsKey("MS_OwinContext"))
return null;
var context = request.Properties["MS_OwinContext"] as OwinContext;
return context?.Request.RemoteIpAddress;
日志:
Exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListenerRequest'. at System.Net.HttpListenerRequest.CheckDisposed() at System.Net.HttpListenerRequest.get_RemoteEndPoint() at Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerRequest.GetRemoteIpAddress() at Microsoft.Owin.Host.HttpListener.RequestProcessing.CallEnvironment.get_ServerRemoteIpAddress() at Microsoft.Owin.Host.HttpListener.RequestProcessing.CallEnvironment.PropertiesTryGetValue(String key, Object& value) at Microsoft.Owin.Host.HttpListener.RequestProcessing.CallEnvironment.TryGetValue(String key, Object& value) at Microsoft.Owin.OwinRequest.Get[T](String key)
【问题讨论】:
-
欢迎,但请分享登录文本。
-
发现这个问题是由于请求在进入'context?.Request.RemoteIpAddress'步骤之前被取消引起的。
-
@zhenm 我现在也有同样的问题 - 如何检查请求是否在此步骤之前被取消?
标签: c# httprequest owin