-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttributes.net
27 lines (24 loc) · 1.1 KB
/
Attributes.net
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
Attributes of ASP.NET Core Actions:
[HttpPost]
[Route(api/orders)]
[Consumes("application/json")]
[Produces("application/json")]
[Authorize("Roles = "customer")]
[ValidateAntiForgeryToken]
[EnableCors("AllowAll")]
[ValidateModel]
[SwaggerOperation("CreateOrder")]
[SwaggerResponse(StatusCodes.Status201Created, "Done.")]
public IActionResult CreateOrder([FromBody] Order order){
return CreatedRoute("GetOrder", new {id = order.id}, order);
}
HttpPost: Indicates that this action should respond to HTTP POST requests.
Route: Specifies the URL path that this action should respond to.
Consumes: Specifies the MIME type that the action can consume as input.
Produces: Specifies the MIME type that the action can produce as output.
Authorize: Authorized for 'customer' role.
ValidateAntiForgeryToken: Protects against CSRF attacks.
EnableCors: Enables CORS for this action, allowing it to be accessed from any origin.
ValidateModel: Ensures that the input parameter meets required constraints.
SwaggerOperation: Adds metadata for Swagger/OpenAPI.
SwaggerResponse: Describing the possible HTTP response codes and their meanings.