Search code examples
c#.netmononancy

Launching 2 and more WebApps


I want to launch 2 or more webApp. How do I do that in .NET? I am newby to C# and .NET.

    class Program
    {
        static void Main(string[] args)
        {
              launchService("localhost:4234");
              launchService("localhost:4265");
        }

        public static void launchService(Component component)
        {
              using (WebApp.Start<Startup>(component.Url()))
              {
                  Console.WriteLine("Running on {0}", component.Url());
                  Console.WriteLine("Press enter to exit");
                  Console.ReadLine();
               }
        }
    }

Solution

  • This should be some thing as below:

    class Program
    {
        static IDisposable app1;
        static IDisposable app2;
        static void Main(string[] args)
        {
              launchServices("http://localhost:4234", "http://localhost:4265");
              Console.ReadLine();
              app1.Dispose();
              app2.Dispose();
    
        }
    
        public static void launchServices(string url1, string url2)
        {
              app1 = WebApp.Start<StartupApp1>(url1);
              app2 = WebApp.Start<StartupApp2>(url2);
        }
    }
    

    Following links may help you further:

    http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api

    OWIN cannot run multiple apps in isolation using webapp.start

    Note: There may be some compilation errors/typos in above code as I have just typed it using my IPad.