Created
March 20, 2024 06:51
-
-
Save pradeepn/fefcd7023148f247a58f7d0786ca35e2 to your computer and use it in GitHub Desktop.
ASP.NET Core 6.0 Bootstrapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///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