I'm developing a web app using Blazor with .NET 6.0.11. Building the application produces a .exe
file that runs Kestrel. How do I change this to HTTP.sys?
When I google for this topic most of the results are from older versions of ASP.NET where code like var host = new WebHostBuilder().UseWebListener(
... goes inside Main()
. But Blazor .NET 6 projects have a different structure, there is no Main()
and no WebHostBuilder
.
The only relevant tutorial I could find covers excellently how to configure either IIS or Kestrel from launchSettings.json
but says nothing about HTTP.sys.
My launchSettings.json
(which launches as Kestrel) looks like:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:10563",
"sslPort": 44364
}
},
"profiles": {
"MyAppName": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "http://localhost:10555",
"applicationUrl": "http://localhost:10555",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
and Program.cs
looks like:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
// [omitted other services added for my app]
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// Configure the HTTP request pipeline.
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
The Program.cs
doesn't mention anything about json files nor Kestrel, I'm not sure how it actually ends up reading appsettings.json
eventually and deciding to use Kestrel.
Background: I created this project initially by following the reference application at learn.microsoft.com.
An answer was found in passing under Configure Windows Authentication in ASP.NET Core .
No changes required to launchSettings.json
or appSettings.json
; and the following code should be added to Program.cs
, before the statement var app = builder.Build();
, obviously:
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
builder.WebHost.UseHttpSys(options =>
{
// set options here if desired
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.