How Azure Web Apps Hosts an ASP.NET 5 Application
I want to write this quick post because figuring out how an ASP.NET 5 application is hosted under Azure Web Apps was a big question for me. Some information is already there on this topic but the concept wasn’t crystal clear because when you look at the packed version of an ASP.NET 5 web application, it has the following structure on disk:
It will even get more interesting when you look inside the wwwroot folder:
We have the static files, bin folder which only contains AspNet.Loader.dll inside it and a web.config file. The most interesting bit here is the information inside the web.config file and this information will be read by Helios:
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="bootstrapper-version" value="1.0.0-beta4-11526" /> <add key="runtime-path" value="..\approot\packages" /> <add key="dnx-version" value="" /> <add key="dnx-clr" value="" /> <add key="dnx-app-base" value="..\approot\src\ConfyConf.Client.Web" /> </appSettings> </configuration>
web.config file gives us enough evidence that the wwwroot is the directory that we need to point IIS to and then Helios will read these application settings information to figure out where the application actually is, where the dependencies and packages are, etc.. Let’s deploy the application using Visual Studio Publish feature. I created a brand new Azure Web App on the fly and hit publish:
When the deployment is completed, the web site is immediately up:
Let’s look at how the directory structure look like after the deployment:
Two interesting bits here are approot and wwwroot folders. The question here is that how Azure Web App knew to look into wwwroot folder. It was actually dead simple but it wasn’t obvious at the first glance. Before showing the answer, let’s have a look what IIS Express does to host an ASP.NET 5 application which will give us an hint on the answer.
I fired up the application through the Visual Studio to get IIS Express host my application. After the application is up, I dug into Task Manager to get the command line arguments for IIS Express:
iisexpress.exe 10736 Running Tugberk 00 33,804 K 33 "C:\Program Files (x86)\IIS Express\iisexpress.exe" /config:"C:\Users\Tugberk\Documents\IISExpress\config\applicationhost.config" /site:"WebApplication10" /apppool:"Clr4IntegratedAppPool" IIS Express Worker Process
This points us to applicationhost.config file and WebApplication10 site inside it. When you look at the site node for WebApplication10, you will see that some of the magic is actually happening there:
<site name="WebApplication10" id="77"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="D:\apps\WebApplication10\src\WebApplication10\wwwroot" /> </application> <bindings> <binding protocol="http" bindingInformation="*:47112:localhost" /> </bindings> </site>
wwwroot is pointed as a virtual directory for the web application here for the root path. So, is this information helping us to see how Azure Web App is hosting our app? Absolutely! It gives us the information that something similar should be configured on Azure Web Apps side that it sees the wwwroot folder as the root. If you navigate to Configure section for your Azure Web App and scroll down to the bottom, you will see the virtual directory configuration there.
Clever! My guess is that this configuration was put there when I was publishing the Web Application through web deploy inside the Visual Studio. Digging into Web Publish Activity output could give us more information about when exactly this configuration is set.