question

bhavna-3740 avatar image
0 Votes"
bhavna-3740 asked lextm edited

why does hosting outside IIS is termed as self hosting?

In general, if a third service provider manages the webserver for me then it is hosted, while if I am by myself managing the webserver then it is self-hosting.

In ASP.NET Core, In both places, I am the one who publishes the code on the server, at the time of IIS it is not called self-hosting? what exactly does "self" means?

For me as a programmer, self-hosting means the application should be able to host itself, which means it must be able to listen to the web requests directly or it must run on its own process. Am I wrong? please someone help me to understand the meaning of "self" in self-hosting.

also, the image Microsoft uses to explain self-host is very confusing to me, as far as I know, IIS uses w3wp.exe to execute the application as
128966-showhim.png


the above image is good, w3wp is the process within that our app executes and IIS is the overall container.

but now, look at this image

128967-showhim1.png

Here the application is the wrapper and Kestral is within the application and the process (dotnet.exe/ application.exe) is the wrapper containing the Kestral, why is it so?

for me, it should be

129041-showhim3.png

why my image is different from Microsoft's image for self-hosting? where am I missing the concept?



windows-server-iisdotnet-aspnet-general
showhim.png (8.4 KiB)
showhim1.png (15.2 KiB)
showhim3.png (6.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered bhavna-3740 commented

kestrel is small event driven web server library. it communicates to AspNetCore modules via HttpContext. There is also a simple library called IISHttpServer that can be used instead of kestrel to communicate via HttpContext.

if you run the asp.net application from the command line (or process.start), the startup code calls the kestrel library to be the web server. this is called self-hosted, because the standalone app is a webserver.

if you use the AspNetCore module to host, it loads the app as a dll, and app startup uses IISHttpServer instead of kestrel as the source of the HttpContext messages.

so, the app code only knows about HttpContext. You can build you own app, and host asp.net app code, and use any transport you want. An example of this is hosting asp.net in electron, where there is no webserver.

better explanation:

https://weblog.west-wind.com/posts/2019/Mar/16/ASPNET-Core-Hosting-on-IIS-with-ASPNET-Core-22

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sir, the worker process should reside within the web server, isn't it? so why does dotnet.exe is outside Kestrel, w3wp is inside IIS and not outside IIS.

0 Votes 0 ·
lextm avatar image
0 Votes"
lextm answered lextm edited

"Self hosting" was a concept introduced in WCF/ASP.NET Web API/SignalR, where you can host such a web service inside a non-IIS process (such as a console app or a Windows service app). This term was defined with such a small scope and widely used that way, because otherwise your web app is hosted inside IIS worker process or ASP.NET worker process. It is not quite applicable to ASP.NET Core, and people don't use it that much in such context.

You can feel free to talk about other things as your own "self hosting", but just make sure your audience understand your context, and won't be confused within the conversation.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sir, the worker process should reside within the web server, isn't it? so why does dotnet.exe is outside Kestrel, w3wp is inside IIS and not outside IIS.

0 Votes 0 ·

The Microsoft diagrams are correct, while yours is completely wrong.

IIIS is a multi-process web server, so there is no concept called "inside IIS" nor "outside IIS". w3wp.exe is just one of the IIS processes that is able to host web applications (in-process mode for ASP.NET Core apps).

When out-of-process mode is configured, dotnet.exe (or yourapp.exe) starts and hosts Core CLR first. And then CLR loads Kestrel to initialize the single process web server along with your web app.

The architecture of IIS and Kestrel differ so much that IIS's process model is not applicable to Kestrel.

0 Votes 0 ·