Eugen
Eugen

Reputation: 2990

Host RestAPI inside IIS

I have a rather simple .NET WebApi application which I'm trying to host inside IIS. Followed all of the instructions from MS site about this. here is the startup method for it.

    public static void Main(string[] args)
    {
        var host = WebHost.CreateDefaultBuilder(args)
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }

I configured the Application pool to not use any managed code but I'm getting still this error in logs

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.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]

I'm out of any ideas what can be wrong. Any suggestions?

Using .NET Core 2.2

Upvotes: 3

Views: 5760

Answers (2)

Recep Duman
Recep Duman

Reputation: 366

I want to use UseKestrel(). When I create .net core 2.0 or 2.1 project. I can use UseKestrel() But If I create .net core 2.2 project I couldn't use UseKestrel()

I solved this problem like that

  • Create new .net core 2.0 or 2.1 project. Then, you can upgrade .net core project to 2.2. It will work.

But it is not effective solution.

Upvotes: 0

Edward
Edward

Reputation: 29976

For InProcess, it uses IISHttpServer.

enter image description here

For your code, you are configuring UseKestrel() which uses out-of-process.

enter image description here

For solution, remove the .UseKestrel() line.

public static void Main(string[] args)
{
    var host = WebHost.CreateDefaultBuilder(args)
                //.UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();
    host.Run();
}

For more details, refer ASP.NET Core Module.

Upvotes: 9

Related Questions