ASP.NET Core – Implementing custom server

By Dawid on (tags: ASP.NET, core, hosting, server, categories: code)

In previous blog post I’ve show you how to host ASP.NET Core application using Kestrel server. But why not to write our own server – in ASP.NET Core that is actually quite simple.

Like show in previous blog post ASP.NET Core provide an extension method which specifies the Kestrel server will be used by the app (it creates the web server and hosts the code). But there is actually another one – . Let’s try to use it and provide our own hosting server.

So how the requests are getting handled in the server?

Each server has collection of server features. Those are interfaces which exposes some functionality of the server. For example feature is exposing information’s about addresses on which server is listening for requests. There is much, much more of those features…

IHttpResponseFeature and IHttpRequestFeature are required by all of the servers – please remember about that! In the ASP.NET everything is about HttpContext but not in ASP.NET Core. In Core, HttpContext is just a wrapper around set of request features. To create one use method on the application object.

The main method of the server is the method – it’s processing each of the request which comes in.

That is basically it, now we just have to wire it up and start using our new server.