Map, MapGet, MapPost, MapPut and MapDelete methods in ASP.NET Core MVC - Routing ASP.NET
namespace MapMethodsRouting
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/Home", async (context) =>
{
await context.Response.WriteAsync("This is Home Page... GET");
});
endpoints.MapPost("/Home", async (context) =>
{
await context.Response.WriteAsync("This is Home Page... POST");
});
endpoints.MapPut("/Home", async (context) =>
{
await context.Response.WriteAsync("This is Home Page... PUT");
});
endpoints.MapDelete("/Home", async (context) =>
{
await context.Response.WriteAsync("This is Home Page... DELETE");
});
});
app.Run(async (HttpContext context) =>
{
await context.Response.WriteAsync("Page Not Found...");
});
//Below is called "Request Delegate" which is defined as shown above :
//async (context) =>
//{
// await context.Response.WriteAsync("This is Home Page... DELETE");
//}
//app.MapGet("/", () => "Hello World!");
//app.Map("/Home", () => "Hello World!"); //By default, GET request works
//app.MapGet("/Home", () => "Hello World! - GET");
//app.MapPost("/Home", () => "Hello World! - POST");
//app.MapPut("/Home", () => "Hello World! - PUT");
//app.MapDelete("/Home", () => "Hello World! - DELETE");
app.Run();
}
}
}
.png)
.png)
.png)
Comments
Post a Comment