Skip to content

Instantly share code, notes, and snippets.

@pradeepn
Created March 20, 2024 06:51
Show Gist options
  • Save pradeepn/fefcd7023148f247a58f7d0786ca35e2 to your computer and use it in GitHub Desktop.
Save pradeepn/fefcd7023148f247a58f7d0786ca35e2 to your computer and use it in GitHub Desktop.
ASP.NET Core 6.0 Bootstrapping
///NEW .net 6.0 WAY
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.MapGet("/", () => "Hello World!");
app.MapRazorPages();
app.Run();
///<!----------------------OLD >net 3 WAY-------------------->
var hostBuilder = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddRazorPages();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.Configure((ctx, app) =>
{
if (ctx.HostingEnvironment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", () => "Hello World!");
endpoints.MapRazorPages();
});
});
});
hostBuilder.Build().Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment