ASP.Net self-hosted application

1.1k views Asked by At

How to control ASP.Net 5 application from console application? All examples of self-hosted application I've found assume that the lifetime of the webserver matches the lifetime of application. Is it possible to have assembly of ASP.Net 5 application with Startup.cs file and main assembly (console app) which allows to start and stop web application using this Startup class when I need? For example, Node.js allows to initiate new server at any place in code, like this

http.createServer(function (req, res) { /* processing request }).listen(80, '127.0.0.1');

Is it possible to implement anything like this in ASP.Net 5?

2

There are 2 answers

1
davidfowl On BEST ANSWER

When you use the hosting API in your Program.Main, you can achieve the same thing.

UPDATE: This is the RC1 API:

https://github.com/aspnet/Hosting/blob/1.0.0-rc1/src/Microsoft.AspNet.Hosting/Program.cs

post RC1 is very different

1
Andrei Tătar On

You can (re)create/(re)start the server when you like during the lifetime of the application.