简体   繁体   中英

Configure IIS as a load balancer for two kestrel servers (for the same website)

ASP.NET Core cannot be run directly in IIS as it requires Kestrel.

This means it is not possible to update a website at runtime like in traditional ASP.NET sites, since the kestrel server have to be shut down during the update.

I want to avoid downtime without adding additional web servers and a load balancer. Is it possible to configure the ASP.NET Core module in IIS to connect to two different Kestrel servers? So if one of them is shut down all requests will go to the other one?

(I was thinking something like having two different folders on disk: C:\\inetpub\\wwwroot\\mysite_instance1 and C:\\inetpub\\wwwroot\\mysite_instance2 , thus shutting one down will enable updates of that instance)

If it is possible, are there any considerations we need to be aware of? For example, do the anti forgery token need to be configured in some way? (I do not use sessions.)

I would also be interested in a neat load balancer mechanism, but don't know any way to do it. Yet, you can perfectly switch the directory targeted by a web application from a directory C:\\inetpub\\wwwroot\\mysite_instance1 to a directory C:\\inetpub\\wwwroot\\mysite_instance2, update instance1 and switch it back, and it should do the job.

This is not currently supported due to the way in which IIS and the AspNetCoreModule works.

IIS passes an IHttpContext object to the AspNetCoreModule. The AspNetCoreModule uses the IHttpContext object to query the physical application path. The module then reads the web.config file found in the directory of the application. Once this has been done the module maintains a 1:1 relationship between the IIS application and the dotnet process.

I've raised this as a question and included some additional details on your behalf.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM