Web API with OWIN throws ObjectDisposedException for HttpMessageInvoker

不打扰是莪最后的温柔 提交于 2019-11-30 20:02:59
Marcus Höglund

This is an old question but a just spent hours trying to beat the ObjectDisposedException and just found a solution which this AspNetWebStack issue on codeplex helped me with:

When your owin web api should run in self-hosting environments you bind the web api config in the owin startup class

public void Configuration(IAppBuilder app)
{
    ConfigureOAuth(app);

    HttpConfiguration config = new HttpConfiguration();
    WebApiConfig.Register(config);
    app.UseWebApi(config);
}

If you intend to use IIS as host for your owin web api then bind the web api config in the global asax class

protected void Application_Start(object sender, EventArgs e)
{
    GlobalConfiguration.Configure(WebApiConfig.Register);
}

This eliminated the ObjectDisposedException and my web api runs like a charm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!