Berger
Berger

Reputation: 273

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.

Upvotes: 4

Views: 11456

Answers (2)

JessieArr
JessieArr

Reputation: 786

This also occurred for me in a new project in which the module was specified as AspNetCoreModuleV2:

  <handlers>
    <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
  </handlers>

Presumably I did not have it installed. I saw that in an older .NET Core website of mine, the module was not V2. Removing the V2 from the module specification fixed it in my instance:

  <handlers>
    <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
  </handlers>

Upvotes: 2

Berger
Berger

Reputation: 273

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.

Upvotes: 6

Related Questions