0

Have tried recommendations as found in HTTP Error 500.30 - ASP.NET Core 5 app failed to start and other similar posts but not having a lot of luck.

My API works perfectly fine running with IIS Express in VS2019, but after publishing it just won't start.

This is my web.config

<?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=".\MyApi.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

Have tried both inprocess and outprocess, provided environment variables no difference.

Code is deployed to C:\inetpub\wwwroot\MyApi

IIS_IUSRS has been given read/write access to wwwroot folder

This is my working lunchsettings.json file from the VS project

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44307",
      "sslPort": 44307
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyApi": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

This is my program.cs

public class Program
{
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                _ = webBuilder.UseStartup<Startup>();
            })
            .ConfigureServices(services =>
            {
                _ = services.AddHostedService<MyApiWorker>().Configure<EventLogSettings>(config =>
                {
                    config.LogName = "My API";
                    config.SourceName = "My API";
                });
            });

    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }
}

IIS logs in /inetpub/logs/logfiles are not all that useful (4443 was the port I used when adding to IIS).

#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2021-10-27 09:31:01
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2021-10-27 09:31:01 ::1 GET / - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 4
2021-10-27 09:31:07 ::1 GET / - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 0
2021-10-27 09:32:39 ::1 GET /swagger - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 0
2021-10-27 09:36:45 ::1 GET / - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 0

Any ideas would be greatly appreciated. I can't seem to find any meaningful logs, and the logs the app outputs never publish anything.

EDIT: Application Pool is No Managed Code Have installed dotnet-hosting-5.0.11-win.exe and rebooted and restarted IIS multiple times.

Event Log shows: Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi' failed to load coreclr. Exception message: Managed server didn't initialize after 120000 ms.

EDIT 2 Now getting this in the Event Logs:

The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID 
{3480A401-BDE9-4407-BC02-798A866AC051}
 and APPID 
{30AD8C8E-AE85-42FA-B9E8-7E99E3DFBFC5}
 to the user IIS APPPOOL\DotNetCore SID (S-1-5-82-2530134163-791093599-2246298441-3166710890-3969430272) from address LocalHost (Using LRPC) running in the application container Unavailable SID (Unavailable). This security permission can be modified using the Component Services administrative tool.

All stdout logs 0kb empty files

EDIT 3 I can also go to the folder and run it by double-clicking the exe, but for some reason, IIS will not. This makes no sense. All I get is this error:

Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi\' failed to load coreclr. Exception message:
Managed server didn't initialize after 120000 ms.

Extending timeout doesn't help either, when manually executing it takes seconds to get up and running.

EDIT 4 I had some Google Gmail functions in the API to send out emails on errors. Seems they were causing a problem. Removed all traces of the google stuff, and it no longer takes minutes to start. I suspect this was because Google was trying to get IIS to accept terms to use Gmail, but that obviously cannot happen.

Now that is out of the way, I am still getting a new error:

Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi\' has exited from Program.Main with exit code = '0'. Please check the stderr logs for more information.

But no stderr messages to be found, but at least the error is different.

devonuto
  • 375
  • 1
  • 6
  • 18

3 Answers3

0

I was able to host on my windows IIS.

Pre-requisite: You need to have .Net Core Hosting Bundle installed on the server.

In IIS Manager,

  1. Created New Website in IIS and point to the folder where you published the code. IIS Website

  2. When the website gets created, the application pool automatically gets created which runs on ApplicationPoolIdentity. Make sure the .Net CLR version is to "No Managed Code"app pool

  3. Reset IIS

Browse the application url: http://:port/<controllername/route>

0
  1. Please make sure that you have installed your .net core on server
  2. Setup your application pool to No Managed Code
  3. If still not working, please check error logs

I follow these steps https://dotnetblog.asphostportal.com/how-to-publish-asp-net-core-blazor-application-to-iis/ and my application work flawlessly.

0

Okay, so I figured it out without any useful logs.

The fact it wouldn't run the Google auth made me start thinking about whether I needed to run the Application Pool as myself, so I set the Application Pool identity as my user account. No dice. So then I found this post: ASP.NET Core Web 3.1 - IIS Express can fetch data from localdb but local IIS can not

Followed what they suggested, now the application reports starting okay. I can see logs that it is running and can hit the endpoints.

Was also able to add back my Google auth for email notifications. Everything is working.

I also took the opportunity to set the timeout for the Application Pool to 0 and set it to Start Mode: Always Running.

devonuto
  • 375
  • 1
  • 6
  • 18