0

Problems deploying .NET Core to IIS. I followed the steps as below:

  1. Created a website using .NET Core 3.1 with Visual Studio
  2. Created website inside IIS (pointing to an empty physical path C:\inetpub\mywebsite and address mywebsite.core.com)
  3. Published my website from Visual Studio into the same folder, C:\inetpub\mywebsite
  4. Host entry to browse from browser e.g. went to drivers\etc\hosts and added line 127.0.0.1 mywebsite.core.com
  5. Installed bundles from here:https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.5-windows-hosting-bundle-installer

Error is:

HTTP Error 500.30 - ANCM In-Process Start Failure Common solutions to this issue: The application failed to start The application started but then stopped The application started but threw an exception during startup Troubleshooting steps: Check the system event log for error messages Enable logging the application process' stdout messages Attach a debugger to the application process and inspect For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265

I have a feeling this might be related to my launchSettings.json file, not sure how it should be adapted...

When I launched my site from Visual Studio it used to open directly to a swagger link, but now after publishing to IIS I can no longer launch it from Visual Studio (unable to connect to webserver IISExpress)... Any help please?

It's a .NET Core 3.1 console app with a Startup that opened a swagger with my APIs before I attempted to publish to IIS.

Later edit: https://learn.microsoft.com/en-us/aspnet/core/test/troubleshoot-azure-iis?view=aspnetcore-3.1 this suggests two possible causes: lack of permission to key vaults (not a preoblem, I am logged in Azure with azure cli); and the other one is: "The app is misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present. Check which versions of the ASP.NET Core shared framework are installed on the target machine."

Later edit: The web.config from C:\inetpub\mywebsite looks like this:

 <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
          </handlers>
          <aspNetCore processPath="dotnet" arguments=".\XXX.MyWebsite.Api.RestApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="outofprocess" />
        </system.webServer>
      </location>
    </configuration>

I actually changed hostingModel="inprocess" to: hostingModel="outofprocess"

And my Project > Properties > Debug looks like this:

enter image description here

(as you can see I changed from In Process to Out of Process)

and the bindings in IIS look like this: enter image description here

UPDATE: After all of this, my error changed to:

HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure Common solutions to this issue: The application process failed to start The application process started but then stopped The application process started but failed to listen on the configured port

(it was initially 500.30)

Not really sure what else to try. How do I check if the port is well configured?

Sami
  • 393
  • 8
  • 22
  • 1
    Does this answer your question? [HTTP Error 500.30 - ANCM In-Process Start Failure](https://stackoverflow.com/questions/53811569/http-error-500-30-ancm-in-process-start-failure) – Vivek Nuna Jun 21 '20 at 09:29
  • 1
    Re keyvault permissions: *you* have access, but what user is the app pool running as in IIS? – pinkfloydx33 Jun 21 '20 at 09:44
  • You can check the error log on by setting true the stdoutLogEnabled on the web.config and let us know what error do you get. You will see the log file on the log folder on your publish folder. It is possible that it is a certificate issue. – Ralph Olazo Jun 21 '20 at 09:47
  • If the server has .NET Core 2.2 installed check to make sure it has the latest update to 2.2. There is a bug in 2.2.1 (I think, don't quote me) that causes this error. You'd think having 3 or 3.1 installed would mitigate that but it doesn't. If that is your problem, you can also publish as self-contained to get it working. – Crowcoder Jun 21 '20 at 10:57
  • Run some basic diagnostics to rule out common mistakes first, https://docs.jexusmanager.com/tutorials/ancm-diagnostics.html Edit your question to include the report if the problem remains. – Lex Li Jun 21 '20 at 13:01
  • pinkfloydx33 : you are right, the app pool was set to use the ApplicationPoolIdentity, I am not sure how to add my Azure credentials to ApplicationPoolIdentity... but I would still expect the site to at least load the swagger, because it doesn't require connection to Azure form the landing page. Any thoughts on how to configure IIS to use azure? When I launched my site from Visual Studio itself, without hosting it in IIS, I would simply login with azure cli and use that managed identity to read from key vaults. (That worked) – Sami Jun 21 '20 at 13:31
  • You do not configure the app pool identity to have access to keyvaults in azure. You [configure your keyvault client with credentials](https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-net-v3#authenticate-to-your-key-vault). Unless you are using the [KeyVault ConfigurationProvider](https://learn.microsoft.com/en-us/aspnet/core/security/key-vault-configuration?view=aspnetcore-3.1), then it is a little different. – Crowcoder Jun 21 '20 at 14:01
  • Crowcoder , so it's not a key vault problem if I could manage to connect with it before using azure cli, right? (before trying to host it in IIS). I installed azure cli, I open it, type "az login" and a page opens where I type my azure credentials, then launched the site in the browser and I could easily access azure. This method is called Managed Identity. – Sami Jun 21 '20 at 15:09
  • @Sami actually, that is not what a Managed Identity is. Managed Identity is service principal for a resource like a vm or an app service. If your webserver is a vm in Azure you should be able to use Managed Identity, but still has nothing to do with the app pool identity. – Crowcoder Jun 22 '20 at 15:55

2 Answers2

1

Try to follow this article.
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/development-time-iis-support?view=aspnetcore-3.1

If it does not work - make sure that your application pool is enabled in IIS for you web application. Try also to restart IIS.

  • "Make sure that your application pool is enabled in IIS for you web application." - thanks Volodymyr. How do you suggest I do this? Actually in IIS I have ApplicationPoolIdentity... but I would still expect the site to at least load the swagger, because it doesn't require connection to Azure from the landing page. When I launched my site from Visual Studio itself, without hosting it in IIS, I would simply login with azure cli and use that managed identity to read from key vaults. (That worked) – Sami Jun 21 '20 at 15:30
  • IIS does not care what do you have on your web site. Swagger is just a component, which integrates as middleware in your request pipeline. As from your screenshot I can see that you are still using "IIS Express", however you should switch it to "IIS". In IIS navigate to Application Pools page, find your pool and make sure that it is enabled. Also for your pool, you should switch setting for you application from Managed to Unmanaged. – Volodymyr Puzdriak Jun 21 '20 at 20:02
  • Volodymyr, thank you. I don't know how I could miss the "IIS Express" thing. You are right. Now I get another error though: AggregateException: One or more errors occurred. (SQLite Error 14: 'unable to open database file'.) Do you suggest I close this question? New error seems unrelated to what was discussed so far. – Sami Jun 21 '20 at 22:17
  • Weird..I got HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure again after restartig the laptop – Sami Jun 21 '20 at 22:43
  • 1) Make sure that you have opened your VS as Administrator 2) Make sure that IIS has access to the folder, where you keep your source code – Volodymyr Puzdriak Jun 22 '20 at 07:39
0

Debugging Via Kestrel Way

Kindly try to publish your application to a particular folder . Dotnet Core Cli Command for publishing. Below command publishes to "output" folder

 dotnet publish -o output

After moving to publish folder via cd command . Type dotnet <project-name>.dll . Use your project name instead of <project-name>

your application should be running and it should be working perfectly . if you face any issue , it is due to application error

Deploy to IIS

After that for hosting your application to production or staging , Install IIS (not express) and .NET core hosting bundle.[click here to download hosting bundle]

After that , you can follow this guide