Simples

<< Click to Display Table of Contents >>

Navigation:  .NET 6 > WebApplication >

Simples

Previous pageReturn to chapter overviewNext page

Crie um novo projeto "ASP.NET Core Empty"

 

Program.cs

 

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

 

app.Use(async (context, next) =>

{

  if (context.Request.Path == "/")

   {

       Processamento p = new Processamento();

       p.Exec(context);

      return;

   }

 

  await next(context);

});

 

app.UseRouting();

app.MapGet("/teste", () => "Hello World!");

 

app.Run();

 

Processamento.cs

 

public class Processamento

{

  public async void Exec(HttpContext contexto)

   {

      await contexto.Response.WriteAsync("<!DOCTYPE html><html><head><meta charset=\"utf-8\"></head><body><h1>Teste de saída</h1></body></html>");

   }

}

 

Saída no navegador

 

http://localhost:5225

 

Teste de saída

 

http://localhost:5225/teste

 

Hello World!