- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 ASP.NET WebApi2 设置中使用 OWIN 时遇到一些困难。重启后的第一个请求会导致异常:
[ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Http.HttpMessageInvoker'.] System.Net.Http.HttpMessageInvoker.CheckDisposed() +327456 System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +24 System.Web.Http.Owin.<InvokeCore>d__0.MoveNext() +501 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +187 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +185 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +64 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +483 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157I believe the problem is caused by a long running task when its hitting the EF DbContext for the first time. All in all the first request is around 4-6000ms. After this first request there are no more exceptions.
I have reproduced the issue in a simplified form with a webapi project and the following OWIN startup (and no global.asax):
public class Startup
{
public void Configuration(IAppBuilder app) {
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
// ---- simulate long running initialization code -------
Thread.Sleep(3000);
// ------------------------------------------------------
app.UseWebApi(config);
}
}
我添加一个 Controller :
[Route("api/test/number")]
public class TestController : ApiController
{
public object Get() {
return 42;
}
}
当我请求此请求时,第一个请求会导致异常。
最佳答案
这是一个老问题,但只是花了几个小时试图击败 ObjectDisposeException,并且刚刚找到了一个解决方案,此 AspNetWebStack issue on codeplex帮助我:
当您的 owin Web api 应在自托管环境中运行时,您可以在 owin 启动类中绑定(bind) Web api 配置
public void Configuration(IAppBuilder app)
{
ConfigureOAuth(app);
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
app.UseWebApi(config);
}
如果您打算使用 IIS 作为 owin Web api 的主机,则在全局 asax 类中绑定(bind) Web api 配置
protected void Application_Start(object sender, EventArgs e)
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
这消除了 ObjectDisposeException,我的 Web api 运行得非常顺利
关于asp.net - 使用 OWIN 的 Web API 会针对 HttpMessageInvoker 引发 ObjectDisposeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33402654/
这是我的代码,不言自明。 using block 终止后 - output 变量被释放。为什么?我想从函数返回它,处理 StreamWriter 但返回我的对象的正确方法是什么? public s
在实现 IDisposable 时,我知道在对象被释放后不应调用的每个方法都应抛出 ObjectDisposeException。但是应该传递给异常构造函数的名称对象的标准是什么? 最佳答案 我认为推
我通常按如下方式将数据发送到事件中心.. var encoded = Encoding.UTF8.GetBytes(serializedString); using (var edata = new
我们正在尝试在 ASP.Net 5 项目中使用 Microsoft 帐户身份验证。我们不需要本地身份验证,也不需要用户名。 在 Web 应用程序的 ASP.Net 5 模板中,使用外部提供商登录后,控
我在 ASP.NET WebApi2 设置中使用 OWIN 时遇到一些困难。重启后的第一个请求会导致异常: [ObjectDisposedException: Cannot access a
以下代码使用 Entity Framework 6 和托管 Oracle 提供程序来调用返回多个游标的 Oracle 存储过程。 using 语句引发以下异常: System.ObjectDispo
我是一名优秀的程序员,十分优秀!