Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 25, 2021 20:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save manoj-choudhari-git/9363e0319c7a9fefac220b975f43ec1f to your computer and use it in GitHub Desktop.
A simplistic ASP .NET Core Web Application
// Program.cs showing Main method
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
// Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
// app.Cors();
// app.UseAuthentication()
// app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
// Default Endpoint
endpoints.MapGet("/", async (context) =>
{
await context.Response.WriteAsync($"Hello World");
});
// Name Token Endpoint
endpoints.MapGet("/{name}", async (context) =>
{
// Read input token and add it to response
var name = context.Request.RouteValues["name"];
await context.Response.WriteAsync($"Hello {name}");
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment