-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiddleware.cs
More file actions
60 lines (52 loc) · 1.51 KB
/
Middleware.cs
File metadata and controls
60 lines (52 loc) · 1.51 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
59
60
using Microsoft.Extensions.Options;
namespace Platform
{
public class QueryStringMiddleware
{
private RequestDelegate? next;
public QueryStringMiddleware()
{
//Do nothing.
}
public QueryStringMiddleware(RequestDelegate nextDelegate)
{
next = nextDelegate;
}
public async Task Invoke(HttpContext context)
{
if (context.Request.Method == HttpMethods.Get && context.Request.Query["custom"] == "true")
{
if (!context.Response.HasStarted)
{
context.Response.ContentType = "text/plain";
}
await context.Response.WriteAsync("Class based middleware\n");
}
if (next != null)
{
await next(context);
}
}
}
public class LocationMiddleware
{
private RequestDelegate next;
private MessageOptions options;
public LocationMiddleware(RequestDelegate next, IOptions<MessageOptions> options)
{
this.next = next;
this.options = options.Value;
}
public async Task Invoke(HttpContext context)
{
if (context.Request.Path == "/location")
{
await context.Response.WriteAsync($"{options.CityName}, {options.CountryName}");
}
else
{
await next(context);
}
}
}
}