Created
May 25, 2021 20:53
-
-
Save manoj-choudhari-git/9363e0319c7a9fefac220b975f43ec1f to your computer and use it in GitHub Desktop.
A simplistic ASP .NET Core Web Application
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
// 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