-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSampleHandler.cs
More file actions
35 lines (32 loc) · 993 Bytes
/
SampleHandler.cs
File metadata and controls
35 lines (32 loc) · 993 Bytes
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
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceComposer.AspNetCore;
namespace Snippets.SampleHandler
{
// begin-snippet: sample-handler-with-authorization
public class SampleHandlerWithAuthorization : ICompositionRequestsHandler
{
[Authorize]
[HttpGet("/sample/{id}")]
public Task Handle(HttpRequest request)
{
return Task.CompletedTask;
}
}
// end-snippet
// begin-snippet: sample-handler-with-custom-status-code
public class SampleHandlerWithCustomStatusCode : ICompositionRequestsHandler
{
[HttpGet("/sample/{id}")]
public Task Handle(HttpRequest request)
{
var response = request.HttpContext.Response;
response.StatusCode = (int)HttpStatusCode.Forbidden;
return Task.CompletedTask;
}
}
// end-snippet
}