当前位置:网站首页>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 中 需要指定 模型绑定的数据源。
边栏推荐
- Tips for using ugui (V) using scroll rect component
- MapReduce project case 3 - temperature statistics
- 【Unity编辑器扩展实践】、查找所有引用该图片的预制体
- 【编解码】从零开始写H264解码器(1) 总纲
- [C language] use of file read / write function
- AcWing 607. Average 2 (implemented in C language)
- 深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
- 2022年理财产品的常见模式有哪些?
- Unity加载设置:Application.backgroundLoadingPriority
- RemoteViews布局和类型限制源码分析
猜你喜欢
JNI confusion of Android Application Security
[Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
EMC RS485接口EMC电路设计方案
【Unity编辑器扩展基础】、EditorGUILayout (一)
智联招聘基于 Nebula Graph 的推荐实践分享
【vi/vim】基本使用及命令汇总
[unity Editor Extension practice] dynamically generate UI code using TXT template
【C语言】NextDay问题
websocket 1 分钟自动断开连接
[C language] three sorting methods for random number files
随机推荐
真正的学懂三极管入门篇(经典)「建议收藏」
2022年理财产品的常见模式有哪些?
模板_大整数乘法
EMC RS485 interface EMC circuit design scheme
【JS】斐波那契数列实现(递归与循环)
Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting
[C language] three sorting methods for random number files
MapReduce project case 3 - temperature statistics
【C语言】如何产生正态分布或高斯分布随机数
【C语言】结构体嵌套二级指针的使用
Ugui force refresh of layout components
Unity load settings: application backgroundLoadingPriority
Unity导入资源后还手动修改资源的属性?这段代码可以给你节约很多时间:AssetPostprocessor
Is tongdaxin stock software reliable? Is it safe to trade stocks on it?
Setting overridesorting for canvas does not take effect
多维度监控:智能监控的数据基础
[unity Editor Extension practice] dynamically generate UI code using TXT template
Bisection (integer bisection and floating point bisection)
Unity Editor Extension Foundation, guilayout
Vivo手机的权限管理