I deployed a API .NET Core 5 service with the Publish feature. When I start the service with cmd with command dotnet <service-name>.dll, it runs but I cannot make API request. When I start it with IIS, it shows me the following error
HTTP Error 500.30 - ASP.NET Core app failed to start Common solutions to this issue: - The app failed to start - The app started but then stopped - The app started but threw an exception during startup Troubleshooting steps: - Check the system event log for error messages - Enable logging the application process' stdout messages - Attach a debugger to the application process and inspect I searched around the internet this error, but I didn't find a solution for my problem. This is my program.cs
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder .UseNLog() //.UseContentRoot(Directory.GetCurrentDirectory()) .UseKestrel() .UseIISIntegration() .UseStartup<Startup>(); //.Build(); }); Errors from EventViewer
.NET Runtime
Application: w3wp.exe CoreCLR Version: 5.0.721.25508 .NET Version: 5.0.7 Description: The process was terminated due to an unhandled exception. Exception Info: 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 LogService.Program.Main(String[] args) in C:\DEV\LogService\LogService.API\Program.cs:line 19 IIS AspNetCode Module V2
Application '/LM/W3SVC/2/ROOT' with physical root 'C:\LogService\' hit unexpected managed exception, exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs: 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 LogService.Program.Main(String[] args) in C:\DEV\LogService\LogService.API\Program.cs:line 19 Application '/LM/W3SVC/2/ROOT' with physical root 'C:\LogService\' failed to load coreclr. Exception message: CLR worker thread exited prematurely