0

I am having problems hosting my .net core 5.0 web api on IIS so I decided to create a basic out of the box version (WeatherForecast). Again this would not work on IIS either (so its not my code I don't think). I have installed the .Net Core Hosting Bundle 5.0 (V5.0.2) and have restarted IIS (net stop was /y, net start w3svc).

My website is hosted at https://authdev.XXXXXXXX.net/api/weatherforecast (where XXXXXXXX.net is on my internal network). The server is Microsoft Hyper-V Server 2019. I have a separate app pool with .Net CLR version set to "No Managed Code" in an integrated pipeline mode. My website is set with appropriate bindings and configured correctly. I have confirmed this by creating a .Net Core 5.0 MVC website (out of the box) that works remotely from this server). I get a 404 in outofprocess mode (and the same url works locally with the obvious server url change). I added logging information at one stage and noticed that public void Configure(IApplicationBuilder app, IWebHostEnvironment env) method in my Startup.cs does not get hit.

Error message 500.30 - ASP.NET Core app failed to start

I think this message indicates that my hosting environment is configured correctly, but that there is an error in my (out of the box) web api.

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseKestrel()
                    .UseIISIntegration()
                    .UseStartup<Startup>();
            });
}

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\WebApplication4.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 9f838b88-2902-4f1d-96d5-468aa0449fb0-->

Startup.cs

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }

I have tried running this in both inprocess and outofprocess modes

InProcess log

crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
      Application startup exception
      System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
         at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
         at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
         at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Unhandled exception. System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
   at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at WebApplication4.Program.Main(String[] args) in C:\Working\dev\sandbox\WebApplication4\WebApplication4\Program.cs:line 17

OutOfProcess log

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://127.0.0.1:43593
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: e:\websites\auth-api
4
  • 1
    Don't call .UseKestrel() when hosting with IIS Commented Feb 7, 2021 at 14:46
  • Thanks for the quick response. I removed the .UseKestrel() and redeployed. I get a 404 in both inprocess and outofprocess modes (I wouldn't expect outofprocess to work without kestrel). log file blank for inprocess mode, but the outofprocess has the familiar info: Microsoft.Hosting.Lifetime[0] Now listening on: 127.0.0.1:36553 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production info: Microsoft.Hosting.Lifetime[0] Content root path: e:\websites\auth-api Commented Feb 7, 2021 at 14:56
  • I can't test it right now, but perhaps the defaults changed and you have to explicitly call UseIIS() as well Commented Feb 7, 2021 at 14:58
  • Sorry, to be honest I have used all three .UseKestrel(), .UseIISIntegration() and .UseIIS() in various combinations with no success. I think ConfigureWebHostDefaults sets some of this up automatically if missing but it just doesn't seem to give me the settings I need. I am curious why my Configure method isn't called in Startup.cs when using inprocess mode on the IIS server. Commented Feb 7, 2021 at 15:02

1 Answer 1

2

Are you sure that you are publishing as a self-contained package? Because if not, your configuration should look like this:

      <aspNetCore processPath="dotnet"
                  arguments=".\WebApplication16.dll"
                  stdoutLogEnabled="false"
                  stdoutLogFile=".\logs\stdout"
                  hostingModel="inprocess" />

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Shawn, thanks for looking at this. I replaced this in my web.config changing the process path to ".\WebApplication5.exe" and the arguments to ".\WebApplication5.dll" I get a 404 and the same error in the log Application is running inside IIS process but is not configured to use IIS server.
Ok, its working now. Thanks for all your help Shawn and Mathias
Shawn, your comments really helped. I don't think I have got it configured 100% correctly because inprocess still doesn't work, but it is now working with outofprocess. Your comment about self-contained package prompted me to reconfigure my publish. It's now self-contained targeting win-x64. The web.config now has <aspNetCore processPath=".\WebApplication5.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="outofprocess" /> which seems to get things working. Also, I also made a mistake with my url it should have been .../weatherforecast not .../api/weatherforecast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.