If deploy an ASP.NET Core as a web app to Azure, what is used for hosting? - azure

ASP.NET Core out of the box supports hosting in IIS and self-hosting scenarios using the Kestrel and WebListener HTTP servers. Accordingly to web.config / project.json looks like IIS is used, but if so it is not clear for my "why" so, as now IIS is acting just as a reverse proxy and the application itself runs as a separate process using the Kestrel HTTP server.
So the main question is "what" and "why" is used by default, if deploy to Azure?

Yes, when you publish to Azure App Services, IIS is used to host your application. As you said, it acts as a reverse proxy to your application, which is running Kestrel HTTP server. But IIS does more than that - it also manages the application process through application pool, which includes or may include:
restarting the app when web.config changes
starting the app on the first HTTP request
running the app as a specified user
recycling the app pool (and effectively restarting the app) on certain conditions
starting multiple app processes
handle webdeploy (this is what happens when you hit "Publish" in Visual Studio

Related

Is a node.js app running on express.js hosted in Azure using IIS?

I'm working on a app that is hosted in Azure.
The app is a web-app based on node.js/express.js.
Is it running on/in a IIS server since it is hosted in Azure?
My app does not use the iisnode package. But i wonder if it is inherently running on IIS since it is hosted in Azure?
Also: As i understand at the moment, IIS-express and express.js is two completely different environments for hosting web-servers.....?
Just according to your description, it seems that you were talking about hosting a node App based on express.js to Azure WebApp for Windows.
Yes for hosting Node.js app in IIS on Azure WebApp for Windows, you need to use iisnode (a native IIS module) to host node.js applications with the web.config file in IIS on Windows. For more details, you can refer to the wiki page iisnode wiki of GitHub repo Azure/iisnode to know what iisnode is, and to know how to host it with a web.config file in IIS via the other wiki page Using a custom web.config for Node apps of GitHub repo projectkudu/kudu.
However, No for Azure WebApp for Windows, because you also can use IIS as a reverse proxy server to handle a Node app via the default port %HTTP_PLATFORM_PORT% specified by Azure WebApp like the blog Running java jar file to serve web requests on Azure App Service Web Apps for Java said. But generally, it's not a recommended way.
Meanwhile, No for hosting Node app on other Azure services, such as Azure WebApp for Liunx, Azure VM, or Azure Container services, these services based on Linux do not require IIS, so the iisnode module also be not absolute required.

Is IHostedService.StopAsync() called when IIS recycles?

This question is with regard to ASP.NET Core 2.2 applications running on IIS, specifically when registering instances of IHostedService with the DI container.
Every article I read about IHostedService.StopAsync() just talks about StopAsync() being called when the host "shuts down", but I want to know what happens when IIS recycles.
My question(s):
1. Is StopAsync() called when the IIS recycles?
2. Is the answer the same regardless of using InProcess hosting or OutOfProcess hosting? (ASP.NET Core supports InProcess as of version 2.2)
Is StopAsync() called when the IIS recycles?
Yes
Reference Implement background tasks in microservices with IHostedService and the BackgroundService class
Deployment considerations and takeaways
It is important to note that the way you deploy your ASP.NET Core
WebHost or .NET Core Host might impact the final solution. For
instance, if you deploy your WebHost on IIS or a regular Azure App
Service, your host can be shut down because of app pool recycles.
.....
note: emphasis mine
which by extension would stop any IHostedService,

How to setup iis in Azure web app service with Net Core 2 app?

I develop simple Web Api on Net Core 2 and add Angular app to it (inside wwwroot folder) and publish it from my VS 2017 IDE to Azure Web App Service. All work fine, but when I reload page of my app in browser, server can't find route. So It often happens when iis not setup for SPA, It's described in https://angular.io/guide/deployment, I must configure the server to return the application's host page (index.html) when asked for a file that it does not have. How I can setup server node of iis in Azure Web App Service (web.config in Net Core 2 was deleted).
I am afraid you cannot achieve this.
Cause: Azure App Services runs IIS so it behaves mostly the same as local IIS, routing requests using a native module called AspNetCoreModule. So, it needs your published web.config file. Even though you deleted the web.config file, Azure would also generate a new web.config file to be used.(Though I don't understand why you delete the web.config file)
Solution:
Even you can upload the web.config file to Azure again, I'm afraid of that it will be ignored and doesn't work. So, I suggest you redeploy your website which contains web.config file to Azure and configure it well.
Additional: Azure Web App service is a kind of PaaS. So, if you want to install IIS manually, you can choose to host your website on a Windows Azure VM.

Hosting a Web Server and Web Service locally on same port

I seem to miss somehting really obvious.
Anyways, i am developing a ReactJs web app and use nodejs (browser-sync) to host a simple web server for testing on localhost. Everything's working fine.
As for the server side i have a REST Service hosted in ASP.NET WebAPI.
I want to keep the urls in the web app relative for deployment reasons (because then it doesn't matter what the hostname is, as long it's running on the same domain).
I know out of experience that it's possible to host a self hosted ASP.NET WebAPI and a Web Application in IIS Express (at least in different paths) at the same time.
But now when i start browser-sync (which uses node http server internally as far as i can tell) and then WebAPI service host, the service host tells me it can't host on this url.
When i start it the other way around, browser-sync automatically increases the port so that it's on the next free port.
Does somebody have experience with it?
EDIT:
My question maybe in a more general sense: How do you develop web apps that are hosted on a local web server (in my case via nodejs) against a local running web service? And do you use relative URLs in your web app? Which leads to the problem that the service and the web have to run on the same server
I solved my problem like this:
ASP.NET WebAPI hosts under a different port then the nodejs web server
I set up a proxy in nodejs webserver for all urls starting with '/api/' and proxy these requests to the WebAPI port
I can use relative URLs in my client

IIS Restart on Updating a Web Application

I have deployed multiple Web Applications in IIS, When I am deploying a modified Dll for any of this Web Application, I need to restart the IIS to get the effect of the new dll. This impacts other Applications. All of these Applications get restarted as I have restarted IIS. Is there any way by which I can restart the specific Application, for which the modified Dll has been deployed?
Yes. Create a different "Application Pool" for your app (in IIS). Make sure your app is assigned to the new pool.
When your app is deployed, the app pool is automatically restarted (affecting all of the other apps in that pool). By default, everything gets deployed to the default app pool.

Resources