Reputation: 3
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
Upvotes: 0
Views: 4442
Reputation: 7458
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" />
Upvotes: 2