当前位置:网站首页>. NETCORE sets the API post mode, which can accept parameters directly in parentheses
. NETCORE sets the API post mode, which can accept parameters directly in parentheses
2022-04-23 03:16:00 【Pingshan CP3】
as everyone knows , stay .NetCore WebApi in ,Post The way of api When receiving parameters, it cannot be like Get those , Write the accepted parameters directly into the brackets after the method , Such as :
[HttpPost]
public string GetAreaGroupList(string id){
return id;
}
This is because api Default inference rules , Binding source reasoning , With the help of these rules , There is no need to manually identify the binding source by applying attributes to the operation parameters , Several of these rules are
[FromBody] Infer complex type parameters . However, it does not apply to any complex built-in type with special meaning , Such as IFormCollection and CancellationToken.
[FromForm] in the light of IFormFile and IFormFileCollection Type of operation parameters .
[FromRoute] Infer the name of any operation parameter that matches the parameters in the routing template .
[FromQuery] Infer from any other operating parameters .
But sometimes I don't want to write so complicated api, Just want to write and accept parameters one by one in parentheses , Then just turn off the default reasoning rules .
.NetCore disable api Rules of reasoning , stay Startup.cs ConfigureServices writes :
services.AddControllers(cfg => { cfg.Filters.Add(new ExceptionHandleAttribute()); })
.ConfigureApiBehaviorOptions(options =>
{
//options.SuppressConsumesConstraintForFormFileParameters = true;// Disable when [FromForm] Property annotation , Reasoning multipart/form-data Request content type
options.SuppressInferBindingSourcesForParameters = true;// Ban api The rules of reasoning , This supports post The method accepts parameters and directly in parentheses model Parameters of the way
});
版权声明
本文为[Pingshan CP3]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220627117167.html
边栏推荐
- Charles uses three ways to modify requests and responses
- Use of ADB command [1]
- Miniapi of. Net7 (special section): NET7 Preview3
- How does Microsoft solve the problem of multiple PC programs
- MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
- Aspnetcore configuration multi environment log4net configuration file
- The most easy to understand service container and scope of dependency injection
- Queue storage and circular queue
- Iotos IOT middle platform is connected to the access control system of isecure center
- 通过 zxing 生成二维码
猜你喜欢

Huawei mobile ADB devices connection device is empty

可以接收多種數據類型參數——可變參數

C WPF UI framework mahapps switching theme

PID debugging of coding motor (speed loop | position loop | follow)

Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!

MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】

C语言实现通讯录----(静态版本)

二进制文件版本控制工具选择难?看完这篇你会找到答案

IDEA查看历史记录【文件历史和项目历史】
![General testing technology [1] classification of testing](/img/f1/d80b6793b6443cbc4048d7e6319f51.png)
General testing technology [1] classification of testing
随机推荐
Two methods are used to solve the "maximum palindrome product" problem
Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
Fiddler use
Preview of converting doc and PDF to SWF file
Miniapi of. Net7 (special section): NET7 Preview3
ASP. Net 6 middleware series - execution sequence
IDEA查看历史记录【文件历史和项目历史】
Huawei mobile ADB devices connection device is empty
Use of metagroup object tuple in C
oracle 查询外键含有逗号分隔的数据
JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
Knowledge of software testing~
[MySQL] left function | right function
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
Web Course Design - his system
General test technology [II] test method
Experiment 5 components and event handling
搭建XAMPP时mysql端口被占用
Student achievement management
[Mysql] LEFT函數 | RIGHT函數