当前位置:网站首页>. 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
边栏推荐
- How does Microsoft solve the problem of multiple PC programs
- 2022a special equipment related management (elevator) work license question bank and simulation examination
- Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
- [untitled]
- Experiment 5 components and event handling
- What kind of experience is it to prepare for a month to participate in ACM?
- Knowledge of software testing~
- 2022t elevator repair test simulation 100 questions and online simulation test
- ASP. Net and ASP NETCORE multi environment configuration comparison
- Eight elder brothers chronicle [4]
猜你喜欢
Maui initial experience: Cool
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
LoadRunner - performance testing tool
Charles uses three ways to modify requests and responses
Iotos IOT middle platform is connected to the access control system of isecure center
超好用的【通用Excel导入功能】
手机连接电脑后,QT的QDIR怎么读取手机文件路径
一套组合拳,打造一款 IDEA 护眼方案
二进制文件版本控制工具选择难?看完这篇你会找到答案
随机推荐
LoadRunner - performance testing tool
ASP. Net 6 middleware series - Custom middleware classes
[mock data] fastmock dynamically returns the mock content according to the incoming parameters
C syntax pattern matching [switch expression]
How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
ASP. Net 6 middleware series - conditional Middleware
The most easy to understand service container and scope of dependency injection
Maui initial experience: Cool
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
7-11 rearrange the linked list (25 points)
This new feature of C 11, I would like to call it the strongest!
Mysql database
2022年做跨境电商五大技巧小分享
可以接收多種數據類型參數——可變參數
A set of combination boxing to create an idea eye protection scheme
Use split to solve the "most common words" problem
Top 9 task management system in 2022
研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
Knowledge of software testing~
超好用的【通用Excel导入功能】