Where does IAppBuilder.UseWebApi come from?
- Posted in:
- ASP.NET Web API
- OWIN
- Self Host
I was converting a self-hosted ASP.NET Web API application from Microsoft ASP.NET Web API Self Host to use OWIN Self Hosting. Everything went find until I tried to add the route configuration to the OWIN pipeline. Samples I found indicate all you have to do is call “UseWebApi” but the IAppBuilder.UseWebApi method did not resolve for me:
After some searching around I found that you will need to import the Microsoft ASP.NET Web API 2 OWIN Self-Host Nuget package.
I didn’t realize that there was a separate Nuget package if you wanted to combine OWIN and ASP.NET Web API. It was a simple solution and honestly now that I think about it, should have been one of the first things I checked. This post is for the next person that runs into this issue.
Comments
I was that person. Thanks!
davidDitto. Thanks a lot for this little nugget of wisdom.
AmiSweet man, thanks so much.
AndyGood
HanuGood
HanuAnd to save the next person a few steps:
erwin1) In VS:
Tools -> NuGet Package Manager -> Package Manager Console
2) Run:
Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
THANKS FOR LETTING US KNOW.
ISHITA<script>alert("Good job!")</script>
MarkThx!
UrsinWhat namespace do you need to import afterwards?
joeIt's in the Owin namespace in System.Web.Http.Owin.dll (which is in the Microsoft.WebApi.Owin package). You'll want need a reference to the assembly.
TochiIt's in the Owin namespace in System.Web.Http.Owin.dll (which is in the Microsoft.AspNet.WebApi.Owin package). You'll need a reference to the assembly.
TochiThank you
NikI realize this post is about self hosted OWIN, but if you are using the OWIN pipeline and hosting in IIS instead, then the package you need to install is:
JoshInstall-Package Microsoft.AspNet.WebApi.Owin.
thanks alot
littlethanks alot
littleGreat, thanks man!
JeanMAGIC !!!
Sourav KingsThanks!!!!
Olamide1
NebulaThanks, I was stumped.
JahmalThanks!!
DarioThanks!
thanksThank you. Saved me some time too
DaveThanks! Well done!!
IssyAnother next person helped - thank you!
DanielPlease refer to the following code -
XFormerusing System.Web.Http;
using DemoWorkerRole;
using Microsoft.Owin;
using Owin;
using System.Web.Http;
[assembly: OwinStartup(typeof (Startup))]
namespace DemoWorkerRole
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
// Routing
config.Routes.MapHttpRoute(
"Default",
"api/{controller}/{id}",
new {id = RouteParameter.Optional});
//Configure WebAPI
app.UseWebApi(config);
}
}
}
While this works in one of the solution, but in the other solution it fails to fins app.UseWebApi. Though none of the referenced dlls are missing. There is so much confusion around using
System.Web.Http
Owin, Microsoft.Owin, System.Web, System.ASP.net.WebpApi.OwinSelfHost...
Just noticed that after installing nuget package - it changes the version of using System.Web.Http from 4.0... to 5.2....
XFormerIt's working now, but I am still looking for an article to clear the various namespaces with respect to OWIN, Microsoft.Owin, Web API2, SelfHosted etc.
Thanks!
Alex Avrutinthanks
talhaBingo. Thanks.
DanSpot on. Many thanks.
PT Esteve