How to run self-hosted(owin based) web api on IIS?

5.9k Views Asked by At

I have developed self-hosted(owin based) web api using console application.

In development phase I was running the console application and everything was okay.

  static void Main(string[] args)
    {

        string baseUri = "http://+:8080";

        Console.WriteLine("Starting web Server...");
        var server = WebApp.Start<Startup>(baseUri);
        Console.WriteLine("Server running at {0} - press Enter to quit. ", baseUri);
        Console.ReadLine();
        server.Dispose();
    }

Now I need to deploy my self-hosted web api to run on IIS.So, could you please tell me the steps to get my web api up and running on IIS?

1

There are 1 best solutions below

2
On

In order to understand theory - take a look at this question. If you want your OWIN self-hosted WEB API application to be running on IIS, you need to use Owin.Host.SystemWeb package. You should:

  • Add a Startup.cs class (entry point for your IIS-hosted app)
  • Tell OWIN pipeline about your entrypoint: Mark Startup class with owin attribute OR do it via web.config. (See this article for reference)

P.S. You can always take a look at a standard scaffolded empty Web API project in Visual Studio. It includes IIS web host out-of-the-box