-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (53 loc) · 2.2 KB
/
Program.cs
File metadata and controls
58 lines (53 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Threading;
using System.Threading.Tasks;
using WeihanLi.Common.Helpers;
namespace MiniAspNetCore
{
public class Program
{
private static readonly CancellationTokenSource Cts = new CancellationTokenSource();
public static async Task Main(string[] args)
{
Console.CancelKeyPress += OnExit;
var host = WebHostBuilder.CreateDefault(args)
.ConfigureServices((configuration, services) =>
{
})
.ConfigureApplication((configuration, app) =>
{
app.When(context => context.Request.Url.PathAndQuery.StartsWith("/favicon.ico"), pipeline => { });
app.When(context => context.Request.Url.PathAndQuery.Contains("test"),
p => { p.Run(context => context.Response.WriteAsync("test")); });
app
.Use(async (context, next) =>
{
await context.Response.WriteLineAsync($"middleware1, requestPath:{context.Request.Url.AbsolutePath}");
await next();
})
.Use(async (context, next) =>
{
await context.Response.WriteLineAsync($"middleware2, requestPath:{context.Request.Url.AbsolutePath}");
await next();
})
.Use(async (context, next) =>
{
await context.Response.WriteLineAsync($"middleware3, requestPath:{context.Request.Url.AbsolutePath}");
await next();
})
;
app.Run(context => context.Response.WriteAsync("Hello Mini Asp.Net Core"));
})
.Initialize((configuration, services) =>
{
})
.Build();
await host.RunAsync(Cts.Token);
}
private static void OnExit(object sender, EventArgs e)
{
Console.WriteLine("exiting ...");
Cts.Cancel();
}
}
}