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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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...
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.