4

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.

Berger
  • 273
  • 1
  • 4
  • 16
  • Have you verified that all files are being transferred via WebDeploy. Does the same thing happen if you FTP the files? – TidyDev Apr 25 '18 at 07:47
  • All files are getting deploed at the server. I have also tried with FTP, same behaviour. – Berger Apr 25 '18 at 07:51
  • What exactly is the error message? – Tanveer Badar Apr 25 '18 at 07:53
  • @TanveerBadar thats the problem, there is no error message. It just puts the files up there and nothing is happening. – Berger Apr 25 '18 at 07:56
  • Did you tried installing the SDK just to make sure it's not related to missing dependencies? Without an error is hard to reason what's going on. Your web.config is exactly like one I have working so.. – jpgrassi Apr 25 '18 at 10:08
  • also, can you start the app from the folder where you deploy? go to the folder were Debdeploy publishes it and run `dotnet Agent.DuZu.Web.dll`. If it works than you can exclude files and package problems. – jpgrassi Apr 25 '18 at 10:12
  • @jpgrassi Starting it manually with dotnet or just the .exe works fine. – Berger Apr 25 '18 at 10:25
  • How does the application pool look like? What do you have configured for it? – jpgrassi Apr 25 '18 at 11:38
  • have you checked the windows event viewer? IIS issues are often logged in it. – Daboul Apr 25 '18 at 13:17
  • @jpgrassi its configured with "No Managed Code" and "Integrated" for Pipeline mode. And of course its started – Berger Apr 25 '18 at 13:21
  • @Daboul I only get Warnings, considering: `The Application Host Helper Service encountered an error trying to delete the history directory 'C:\inetpub\history\CFGHISTORY_0000000054'. The directory will be skipped and ignored. Note that the directory may still get deleted in the future if the service restarts. The data field contains the error number.` – Berger Apr 25 '18 at 13:30
  • "but the Application just won't start" what makes you say that? when you send a request to your web app, you don't get a dotnet.exe process in memory? is there a request you can use that is working when you launch it manually with dotnet and that is failing when sent to IIS? you don't get any message returned from IIS to your browser? – Daboul Apr 25 '18 at 14:46
  • If the app runs from the console, but not from IIS, the only thing that makes sense is that you're missing the hosting runtime and/or have not yet restarted your server. – Chris Pratt Apr 25 '18 at 15:02
  • @ChrisPratt I would agree, but that should write a clear log in the event viewer. On a brand new VM, earlier today, I run into that same issue and got a clear: Application 'MACHINExxx' with physical root 'C:\xxx\' failed to start process with commandline 'dotnet .\xxx.dll', ErrorCode = '0x80070002 : 0. And indeed, as you are saying, I had to restart the server after the installation of the hosting runtime. Any reason why he wouldn't get any log? – Daboul Apr 25 '18 at 15:07
  • Is there something I am missing, like restarting the server, wich strts the application, if not started autimatically? – Berger Apr 25 '18 at 15:14
  • Check %SystemRoot%\System32\LogFiles\HTTPERR and also verify your NTFS permissions. – Mark G Apr 25 '18 at 22:14
  • @MarkG HTTPERR won't help me if the application is not running and therefore not processing any requests. What permissions do I need on the applications folders? – Berger Apr 26 '18 at 05:45

2 Answers2

6

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.

Community
  • 1
  • 1
Berger
  • 273
  • 1
  • 4
  • 16
2

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>
JessieArr
  • 767
  • 6
  • 11