Search code examples
azureiis.net-6.0azure-virtual-machine

.NET Website hosted on Azure Windows VM - IIS Web Server fails to work after Server (VM) restart


Hosted a .NET 6 basic Web App in IIS Web Server inside the Azure Virtual Machine (Windows 2016 Data Center)

Commands:

dotnet new webapp
dotnet run
dotnet publish -c Release

3rd command is used for placing release folder files in the Site Physical Path created in IIS Web Server:

enter image description here

It shown the result as welcome page. After VM Stop and Start action, it is showing the localhost as "The Site can't be reached"

If I create new site on Connections of the IIS Manager, then it is working. Every time after restarting the VM, Creating New Site is not the solution. Why previously created Site is showing me "The Site can't be reached" error.

What I have tried:

  1. Tested by creating new Site in Connections of the IIS Manager, it worked for the new site but after restarting the VM, it also stopped working and showing above mentioned error.
  2. Checked VM Status, it is Healthy
  3. All required tools are installed in the VM (VS Code, .NET 6 SDK, Runtime, and Hosting Bundle)

Note: It is working successfully after I clear the cache in the browser after server restart (stop and start) but why I have to clear the browser cache every time after VM stop and start?

Update:

Forgot to mention this:

I have given HTTPS binding to the IIS Manager Website Hosted so if do localhost with port 80, it will shows IIS Web Served Home Page and localhost with Https (443), it will show the hosted website content.

After Server Stop and Start, localhost with port 80 gives the IIS Web Served Home Page and localhost with Https is not giving the website content, here it is giving error "The site is not reached".

Fix:

I have found the fix to this issue which is:

Hosting works with particular time period. Every time when you launch the Website hosted in VM through IIS Web Server after Server restart (several hours), you need to re-host or create new site in IIS Manager Pool.


Solution

  • I tried to reproduce the same in my environment and I got the results like below:

    I have created sample website and when I tried Stop and Start action, localhost reached successfully:

    enter image description here

    enter image description here

    As suggested by samwu you can check event viewer like below:

    In start -> select event viewer -> click Windows Logs node

    enter image description here

    Select application Event Log and Search for errors associated with the failing app like below

    enter image description here

    You can make use of Debug Diagnostics tool.