我使用 C# 创建了 ASP.NET Core 6 Web API。
当我将
app.Run();
文件中的 program.cs
更改为:
app.Run(async context =>
{
await context.Response.WriteAsync("I'm upgrading!\nTRY AGAIN LATER");
});
应用程序不向我显示消息,也无法打开! 有谁知道原因吗?
我尝试更改管道,但没有成功。
我的
program.cs
文件现在是这样的:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run(async context =>
{
await context.Response.WriteAsync("I'm upgrading!\nTRY AGAIN LATER");
});
试试这个:
// ...
app.Run(async context =>
{
await context.Response.WriteAsync("I'm upgrading!\nTRY AGAIN LATER");
});
app.Run();