简体   繁体   中英

Deploy WebAPI (aspnetcore 2) to IIS

Hoping someone can spot something I am doing wrong. I have a solution (VS2017 & .Net Core 2) that contains an MVC DLL and a WebAPI DLL. These work fine locally on IISExpress and I can start both (via multiple startup projects) and have them communicate with each other (localhost:5000 & localhost:7902).

I was ready to deploy to a DEV server (our dev staging server) and created build steps on VSTS. Build went well, then created the Deployment definitions (again on VSTS). The MVC app works well (uses https binding with a hostname). However, and this is where the issue is, the WebAPI also deployed successfully but IIS won't start it. I can run it locally on the server fine using the CLI (dotnet Jbssa.MasterData.Api.DLL) and it works fine. But using the https binding doesn't even attempt to start the server.

I have checked the webconfig and it appears correct (compared to the MVC version).

<?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=".\Jbssa.MasterData.Api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

The binding is configure exactly the same for both sites (https, 443, hostname and certificate) expect the hostname masterdataapi-dev.jbssa.com.au vs masterdata-dev.jbssa.com.au (these are internal applications and are not exposed to the internet. We use Swagger/Swashbuckle to document the API and this page just returns a 404.

I don't even know where to start looking or what additional information you need to help. It is as if IIS doesn't even recognise the API site and won't run the handler in the web.config. I need the API to be a complete site in it's own right as many clients (both web and thick client) will access it. It will become one of many as soon as we can figure out why it won't start.

I added Serilog logging to the and it normally outputs a "Starting host" as the first statement but it isn't shown, in fact no log file is created.

 public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .ReadFrom.Configuration(Configuration)
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .CreateLogger();

            try
            {
                Log.Information("Starting host");

                var host = BuildWebHost(args);

                host.Run();
                return 0;
            }
            catch(Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
                return 1;
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }

The log file is created when running via IIS Express, or via the CLI.

EDIT: Please note that other core both 1.1 and 2.0 site run fine on the server, this is the first API we have deployed so no "Home" landing page or wwwroot folder. not sure if that has anything to do with it. EDIT : Sorry not a 404. here is an image of the result. can't see the response code: 回应图片

This issue turned out to be a missing CNAME entry on the server. Once added the API started working as designed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM