2

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?

Simple Code
  • 2,354
  • 2
  • 27
  • 56

1 Answers1

3

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

n.prokhorov
  • 930
  • 7
  • 13
  • I just can't seem to get this to work. IIS just tried to display files. Do you need to change the project type (it's a console app still) or anything like that? I'd love it if I could run both ways... – Mladen Mihajlovic May 07 '19 at 08:43
  • 3
    Yes, without proper web.config file and global.asax in your application package IIS won't consider site as .net web application. If you want your application to be self hosted + IIS hosted simultaneously, you can create additional projects in your solution: one of type console application and another web application (VS will scaffold config, asax and all IIS-startup stuff for you). This projects will refer the same assemblies of you application, but differ from startup perspective: one for IIS, another for self-hosted console app – n.prokhorov May 08 '19 at 09:17