kestrel in asp.net core - asp.net-core

let's say you have multiple applications on a server. Is there is 1 kestrel instance handling multiple applications request or will there different kestrel instances handling different asp.net core web applications?
Can anybody provide me any links or a post where i can find out how a request travels from the client to server for ASP.NET core applications. see this SO post without an answer. The Relationship of Kestrel server and Program.cs in ASP.NET Core request processing

Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates. For the http request process, you could check this article:
So, from the above document, we can see that each Asp.net core application will have their own Kestrel server to host the application. And, by default when using Kestrel, ASP.NET Core binds to: http://localhost:5000 and https://localhost:5001, if there have multiple applications, you should set them use different port or endpoint. Reference: Configure endpoints for the ASP.NET Core Kestrel web server.

Related

What is the difference between using Kestrel Server or SignalR Server in ASP.NET Core?

As far as my understanding, SignalR allows you to add real-time functionality to web applications by allowing “server to client” and “client to server” communication. It runs on a specified port, which can be used for communication.Hubs need to be created with functions to be called.
Krestel server is a type of minified IIS server, which also runs in a given port and client application can connect to that port.
So, my question is what is the difference between using SignalR or Krestel server, since both run on given port and client applications connect to that port?
Remember that the idea of all frameworks is to encapsulate complexity!
Kestrel is the default, cross-platform Web server implementation that Microsoft implemented in the ASP.NET Core framework, just as Tomcat is the default on Spring Framework for Java.
More Info here
Kestrel, as a Web Server, handle traffic coming from outside to your app through http, and in the case of SignalR it also handles traffic bidirectional through webSockets, and it also can handle http/2 and others.
Remember that WebSockets is a different protocol on layer 7 just like http or https, websockets go through ws or wss these are also managed by a web server like Kestrel.
This being said, SignalR is just a library, part of the ASP.NET Core framework to handle WebSockets and other types of connections, making it easier for you as developer to build applications, abstracting all the complexity of:
a Web Server (Using Kestrel)
WebSockets (Using SignalR)
More info here
As Andy says, the Signalr is a kind of service which running on the kestrel. In my opinion, it is a web framework like MVC or web api.
We will add the Signalr like a service as MVC , Razor Pages and add its routes like below:
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddSignalR();
}
Endpoint:
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapHub<UserActivityHub>("/active");
});
The kestrel is a webserver, which is used to host the core application. It will listen for HTTP requests and surfaces them to the app as a set of request features composed into an HttpContext. Details about kestrel server ,you could refer to this article.

Web.Config file in ASP.NET Core

Do configurations specified in web.config in ASP.NET core apply only to IIS Server or it applies to all non IIS servers?
So far it seems the web config is just for the IIS. Standalone hostings with kestrel would not use it.
The web.config will only be used for IIS. It is used to tell IIS to use aspnetcore module and enable some specific setting when host the asp.net core application on IIS.
If you want to host asp.net core application on another server, the asp.net core application will use kestrel.
If you want to modify the kestrel setting, you could use appsetting.json.
More details, you could refer to this article.

Can a Worker Service be called and/or used inside an existing ASPNET.Core web project?

I've been reading and learing about the new Worker Service features provided in .Net Core 3.0. I have been using this link from Microsoft: Background tasks with hosted services in ASP.NET Core
What I don't understand is this, can these worker service concepts be introduced into an existing ASPNET Web Project, like a Razor Pages site? Or must you create a new project and then deploy that project as a service using whatever mechanism the host OS proivdes for that?
Yes, you can host any number of hosted services (IHostedService) within ASP.NET Core applications. With version 3, ASP.NET Core uses the generic host (Host.CreateDefaultBuilder) which is the framework that is hosting these hosted services when the application starts. In fact, the ASP.NET Core web application is an IHostedService itself.
To add additional hosted services to your ASP.NET Core application, just register additional hosted services with your service collection, e.g. within the Startup’s ConfigureServices:
services.AddHostedService<MyHostedService>();
That service will then launch together with the ASP.NET Core web server when the application runs.
The Worker SDK that is mentioned in the documentation is actually a subset of the Web SDK that you are using with ASP.NET Core application. Microsoft.NET.Sdk.Worker is basically Microsoft.NET.Sdk.Web without the web-specific stuff like Razor compilation and wwwroot folder stuff. It basically sets up automatic file globbing e.g. for the appsettings.json and does some other useful things that the core Microsoft.NET.Sdk does not have.
Ultimately this means, that when you are using the Web SDK, then you already have everything the Worker SDK offers. So you do not need to specify the Worker SDK just to host additional background services.

.NET Core Hosting Bundle

As far as I understood the Docs, the .NET Core Hosting Bundle installs the .NET Core Runtime, .NET Core Library and the ASP.NET Core Module.
It seems that there's a Bundle for every version of the .NET Core Runtime (2.0.6, 2.0.7, ...).
If I have a self contained deployment of my app, I still need the ASP.NET Core Module. However I don't see that the Module can be downloaded separately without the full bundle. Is there a place where I can download it ?
If not:
What's the point of having a self contained application, if I still need to install the whole .net core sdk/runtime bundle on my IIS Server?
There is no official download of the ASP.NET Core Module for IIS ("ANCM"), though it can be installed by calling the hosting bundle installer with OPT_INSTALL_LTS_REDIST=0 OPT_INSTALL_FTS_REDIST=0 as arguments (at least for 1.0-2.0 installs).
What's the point of having a self contained application, if I still
need to install the whole .net core sdk/runtime bundle on my IIS
Server?
Apart from the installer being able to install only ANCM, do not forget that IIS is not the only hosting option for ASP.NET Core Applications. People may still opt to host it on linux or as a Windows Service. Either being exposed to the public Internet (which is supported from 2.0+) or behind NGINX/Apache/…
It is also very useful to deploy preview, daily or custom builds of any component inside .NET Core / ASP.NET Core if needed.
Check the docs on this topic.
The ASP.NET Core Module is a fork of HttpPlatformHandler which was modified to work with ASP.NET Core's new system and was previously used to host ASP.NET Applications. related GitHub issue
IIS needs it in order to start up your ASP.NET Core application when the first request arrives and to route requests to the ASP.NET Core application.
With .NET Core (and hence ASP.NET Core), ASP.NET Core comes with its own http server (previously this was only possible with Http.sys aka WebListener self-hosting, i.e. commonly used for WCF services). It also redirects a couple of headers to the application, since IIS with ASP.NET Core only acts as reverse proxy.
In other words, ASP.NET Core is hosted outside the IIS process, and ASP.NET Core Module is there to communicate with it and starts the outside process if not already. This also means, that ASP.NET Core applications hosted in IIS are subject to IIS lifetime cycle (i.e. IIS may and will stop your applications when idle - This doesn't happen when you self-host your application or use something like nginx as reverse proxy).
With ASP.NET Core 2.1 preview1 it will also be possible to host ASP.NET Core application in the IIS process (w3wp.exe) for a improve request throughput. For more information on this, read ASP.NET Core 2.1.0-preview1: Improvements to IIS hosting

ASP.NET core fails on with

I try to do a performance test on my asp.net core 1.0.1 website. I use loader.io to get 4000 client's to load the website but I get an error on asp.net core. If I run the same code in asp.net 4.6 it runs error on same server. Can anybody tell my why I can't handle same load on my asp.net core site like my asp.net 4.6?
Error:
502 - Web server received an invalid response while acting as a
gateway or proxy server.
There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.
ASP.NET 4.6: https://thusan.tinytake.com/sf/MTA4Mzg1OF80MzMzNzMz
ASP.NET core: https://thusan.tinytake.com/sf/MTA4Mzg1OV80MzMzNzM0
I'm running both sites from IIS on a Windows 2012 r2.
In ASP.NET 4, IIS hosts the web site in its own process. ASP.NET Core changed this. ASP.NET Core web sites execute as a separate process and IIS uses the ASP.NET Core Module to reverse proxy requests to the ASP.NET Core process. The error you are seeing could be caused by many problems, such as a setup errors or hung requests in the ASP.NET Core process.
If all requests fail, it is probably a setup error. Follow this document to make sure guide you have completed all steps to deploy an ASP.NET Core app to IIS. https://docs.asp.net/en/latest/publishing/iis.html.
If the ASP.NET Core site works for a few requests but fails under stress, checkout some of these recommendations for improving performance. https://github.com/aspnet/IISIntegration/issues/245#issuecomment-242541999