0
votes

I have a .net core web api application, on localhost it was working fine both on iis express and default iis. On my web server, I want to host my application as a sub-app under a Asp.Net v4.0 application. I have created a sub application and deployed my core app, then created a no managed app pool and chosen this app pool for my net core sub-app. I have fully installed .net core 2.0 windows hosting bundle and .net core 2.0 SDK.

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=".\MyApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

StartUp class' Configure method

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
{
    logger.AddFile(Configuration.GetValue<string>("LogPath"));
    app.UseDeveloperExceptionPage();
    app.UseDatabaseErrorPage();
    // Enable middleware to serve generated Swagger as a JSON endpoint.
    app.UseSwagger();

    // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyAppV1");
    });


    app.UseMvc();
    //app.UseMiddleware<LoggingMiddleWare>();
}

Program.cs

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

So when I call an endpoint from api, It returns 500 Internal server error.

Despite my stdoutlog is enabled, there is not any log file being created, can not see any proper event logs as well.

2
Did you go over the IIS configuration, troubleshooting tips and common errors section of docs.microsoft.com/en-us/aspnet/core/publishing/iis ?Martin Ullrich
@MartinUllrich I did what this document says, however, there is very limited information about hosting .net core app as a sub app under .net 4.0 app pool, and this info is here, it just shows logging config, I couldn't get if what I am doing is viable or how I can overcome my error.ibubi

2 Answers

2
votes

There's really not enough here to definitively answer your question, but based on the fact that you're hosting it as a virtual application under an ASP.NET 4 app, the most likely culprit is the Web.config. Web.config files are inherited by applications. As a result, anything in your main app (ASP.NET 4) Web.config, not explicitly defined differently in your sub app (ASP.NET Core app) Web.config, comes along for the ride, and there's very likely quite a bit in there that's not compatible with an ASP.NET Core app.

The only real ways to prevent this is to edit the main app's Web.config and explicitly add inheritInChildApplications="false" to pretty much every config section. This has to be done for each section individually; there is no global way to disable inheritance.

There's no guarantee that someone won't modify the parent Web.config with something and forget to add this attribute to the new section, either, so this is also a very brittle solution. In general, it's a bad idea to nest ASP.NET applications, and it's an even worse idea to nest an ASP.NET Core application. I would suggest simply giving it its own site and hosting on a subdomain. You'll have far less issues that way.

0
votes

Despite my stdoutlog is enabled, there is not any log file being created

Check in the Event Viewer (Windows + R, type eventvwr) if the app has the permissions to create the logs directory (look in Windows Logs / Application).

One of the workarounds is to create the logs folder in the deployment directory specified in IIS (at the same level as the Web.config, according to the stdoutLogFile=".\logs\stdout" setting)

Hope this will help you to find the reason of the 500 error in the logs


Edit: you can create the logs directory during the publish process as described here