ASP.NET Core Web API pipeline Does Not Work As expected

39 views Asked by At

I have created an ASP.NET Core 6 Web API using C#.

When I changed app.Run(); in program.cs file to this:

app.Run(async context =>
{
    await context.Response.WriteAsync("I'm upgrading!\nTRY AGAIN LATER");
});

The application does not show me the message and does not open either! Does anybody know the reason?

I tried to change the pipeline but it didn't work.

My program.cs file is now like this:

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");
});
1

There are 1 answers

0
Nick Natsvlishvili On BEST ANSWER

Try this:

// ...

app.Run(async context =>
{
    await context.Response.WriteAsync("I'm upgrading!\nTRY AGAIN LATER");
});

app.Run();