当前位置:网站首页>ASP.NET CORE Study04
ASP.NET CORE Study04
2022-06-28 12:19:00 【人类群星闪耀时】
Binding source Attributes
借助 binding source attributes 可以将请求传递的数据传递给 api,详细的attribute 如下图。
但 在 api 项目下的 标识了 apicontroller 的controller下,binding source attributes 的规则 有所改变
HttpHEAD
head 也是一种http 请求方法,他跟 get 方法非常相似。重要的不同在于 head 方法不会返回 body ,只有响应头信息。
head 可以用来在资源上获取一些信息。
在 asp.net core 提供了HTTP attribute HttpHead 使用,非常方便。
过滤 和 搜索
过滤:首先是一个完整的集合,然后根据条件把匹配/不匹配的数据项移除。
搜索:首先是一个空的集合,然后根据条件把匹配/不匹配的数据项往里面添加。
注意过滤 的字段 只能对 对外暴露的DTO 类的字段值进行过滤。
asp.net core 异常处理
开发模式下,程序出现未想到的异常,通过异常处理返回给用户具有提示性的信息,而不是直接返回异常信息,安全性存在隐患。
是 startup类的configure 方法进行配置。
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// 使用useexceptionhandler 中间价来简单处理异常
app.UseExceptionHandler(appBuilder =>
{
appBuilder.Run(async context =>
{
context.Response.StatusCode = 500;
await context.Response.Body.WriteAsync(System.Text.Encoding.Default.GetBytes("Unexpected Error"));
});
});
}
http 安全性和幂等性

HTTP 各个方法的详解
根据 http 方法的安全性和幂等性的了解,在各种业务场景下使用什么方法可以提供参照。
传递复杂 Action 参数
当Action 需要的参数较多时,通过形参直接传递,会导致代码非常冗余,因此需要使用 模型类 来接受复杂参数,处理复杂参数的传递。
首先需要声明 模型类 ,就是基本的简单的普通 c# 类
public class CompanyDtoParameters
{
public String CompanyName {
get; set; }
public String SearchTerm {
get; set; }
}
注意属性的名称就是请求传递的数据的键名。
然后在 service 类中使用 和 controller 中使用


注意 controller 中 需要指定 模型绑定的数据源。
边栏推荐
- AcWing 606. Average 1 (implemented in C language)
- 30套JSP网站源代码合集「建议收藏」
- Given two points and a point with a middle scale, find the coordinates of the point
- Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
- AsyncTask经验小结
- Url追加参数方法,考虑#、?、$的情况
- 分页样式 flex设置成在尾部显示(即使页数加长 也不会因为在末尾而换行)
- 如何获取泛型的类型
- Unity加载设置:Application.backgroundLoadingPriority
- websocket 1 分钟自动断开连接
猜你喜欢

【Unity编辑器扩展基础】、EditorGUILayout (三)
![[C language] use of nested secondary pointer of structure](/img/59/8b61805431e152995c250f6dd08e29.png)
[C language] use of nested secondary pointer of structure

开源项目维权成功案例: spug 开源运维平台成功维权

已知两个点和中间一个比例的点,求该点坐标

Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques

【C语言】关于scanf()与scanf_s()的一些问题

UGUI使用小技巧(六)Unity实现字符串竖行显示
![[unity Editor Extension Foundation], editorguilayout (I)](/img/f2/42413a4135fd6181bf311b685504b2.png)
[unity Editor Extension Foundation], editorguilayout (I)

Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration

分页样式 flex设置成在尾部显示(即使页数加长 也不会因为在末尾而换行)
随机推荐
【C语言】NextDay问题
运维思考 | 你知道CMDB与监控是什么关系吗?
Map排序工具类
关于字符串转换的一些小技巧
Levels – 虚幻引擎场景制作「建议收藏」
Mr. Zhang responded to the first live broadcast with goods
MapReduce项目案例3——温度统计
Source code analysis of ArrayList
AcWing 606. Average 1 (implemented in C language)
【Unity编辑器扩展基础】、EditorGUILayout (三)
Custom title bar view
UGUI使用小技巧(六)Unity实现字符串竖行显示
[unity Editor Extension practice] dynamically generate UI code using TXT template
【Unity编辑器扩展基础】、EditorGUILayout(二)
【vi/vim】基本使用及命令汇总
Setting overridesorting for canvas does not take effect
Is there a threshold for opening futures accounts? How to open futures accounts safely on the Internet
[C language] use of file read / write function
[C language] about scanf() and scanf_ Some problems of s()
EMC RS485 interface EMC circuit design scheme