Created
December 26, 2018 17:37
-
-
Save musukvl/24e7c76bb4cd60ba55a405aacd49ff17 to your computer and use it in GitHub Desktop.
ASP.NET Core Hello Word with SampleMiddleware
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
using System; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace WebApplication1 | |
{ | |
public class Program | |
{ | |
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | |
WebHost.CreateDefaultBuilder(args) | |
.UseStartup<Startup>(); | |
public static void Main(string[] args) | |
{ | |
CreateWebHostBuilder(args).Build().Run(); | |
} | |
} | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
} | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
app.UseMiddleware<SampleMiddleware>(); | |
app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); | |
} | |
} | |
public class SampleMiddleware | |
{ | |
private readonly RequestDelegate _next; | |
public SampleMiddleware(RequestDelegate next) | |
{ | |
this._next = next; | |
} | |
public async Task Invoke(HttpContext context) | |
{ | |
Console.WriteLine($"{context.Request.Path}{context.Request.QueryString}"); | |
await this._next(context); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment