Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net Core WebAPI not starting behind IIS

I am trying to host a ASP.net Core WebAPI like the Microsoft Docs tell me: Hosting in ASP.NET Core

Configuration

I am Running IIS 10 on Windows Server 2016, where Web Deploy 3.6, .Net Core Runtime 2.0.7 and .NET Core Server Hosting Bundle is installed.

The Web API is configured as follows:

Program.cs :

public static IWebHost BuildWebHost(string[] args) {
    IConfigurationRoot config = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json")
        .Build();

    return WebHost.CreateDefaultBuilder(args)
              .UseConfiguration(config)
              .UseStartup<Startup>()
              .UseKestrel(opt => {
                  opt.Listen(IPAddress.Loopback, 4000);
              })
              .UseIISIntegration()
              .Build();
}

web.config :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
    <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\Agent.DuZu.Web.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>

On the IIS, the ASP.net Core Module is activated and i have a Site with a binding on port 80.

Problem

I am publishing the App on the server with WebDeploy, but the Application just won't start. There is no Output nor Error. I'm not sure if i am missing something or if my Configuration is just fail. Also I would like to know, if there is a way to see the running App.

like image 261
Berger Avatar asked Aug 30 '25 15:08

Berger


1 Answers

With the help of my collegue i figured out the solution:

Permissions:

The IIS has to have Permissions on the site folders. One has to check, that the applicationpool user has permission on the Folders.

I have granted the "LOCAL SERVICE" on my "C:\inetpub\sites" folder where all my sites belong, as well as on the application pool i am using.

web.config

The WebDeploy has overwritten the web.config and changed it to:

<aspNetCore processPath=".\Agent.DuZu.Web.exe" 
    arguments=".\Agent.DuZu.Web.dll"
    stdoutLogEnabled="true" 
    stdoutLogFile=".\logs\stdout" 
    forwardWindowsAuthToken="false" />

So the stdout log showed an Argument Error. The Solution to this is changing the processPath to "dotnet" as described in this question.

<aspNetCore processPath="dotnet" 
    arguments=".\Agent.DuZu.Web.dll"
    stdoutLogEnabled="true" 
    stdoutLogFile=".\logs\stdout" 
    forwardWindowsAuthToken="false" />

Another thing to mention is, that the "logs" folder has to be created, because IIS won't do this by itself.

like image 121
Berger Avatar answered Sep 02 '25 05:09

Berger