Tuesday, January 13, 2015

Setting up an ASP.NET Web API Web Host

If you are creating several ASP.NET Web API Class Libraries and you want to host them in a Web Host (i.e IIS), then you can create a separate ASP.NET Web API Web Host project.

Of course, the easiest way to do this is to create a standard ASP.NET Web API Web Application project since it already supports the Web API Web Host libraries.

However, if you want to create your own customized ASP.NET Web Host project without the unnecessary folder structure from Web API and MVC, you can do the following:

  1. Create an empty ASP.NET Web Application
  2. Add a NuGet package for Microsoft ASP.NET Web API Web Host
  3. Add any necessary folders to run your ASP.NET Web API project such as your Global.asax file, App_Start folder etc.  
  4. Since most of your Controllers are probably residing in your ASP.NET Web API Class Libraries, you will not need to create any Web API Controllers in the Controllers folder and instead only use these Controllers for ASP.NET MVC Views that you want to display (such as for authentication against your Web API)
  5. Verify that you can now access all of your ASP.NET Web API Controllers from your Web Host.  If so, then your project is working correctly!  

No comments:

Post a Comment