ABP框架系列之五十三:(Web-API-Controllers-Web-API-控制器)
Introduction
ASP.NET Boilerplate is integrated to ASP.NET Web API Controllers via Abp.Web.Api nuget package. You can create regular ASP.NET Web API Controllers as you always do. Dependency Injection properly works for regular ApiControllers. But you should derive your controllers from AbpApiController, which provides several benefits and better integrates to ASP.NET Boilerplate.
ASP.NET样板集成到ASP.NET Web API控制器通过abp.web.api NuGet包。您可以创建普通的ASP.NET Web API控制器总是为你做的。依赖注入为规定的apicontrollers正确的工作。但是你应该得到你abpapicontroller控制器,它提供了几个好处,更好的融入到ASP.NET样板。
AbpApiController Base Class
This is a simple api controller derived from AbpApiController:
public class UsersController : AbpApiController
{ }
Localization
AbpApiController defines L method to make localization easier. Example:
public class UsersController : AbpApiController
{
public UsersController()
{
LocalizationSourceName = "MySourceName";
} public UserDto Get(long id)
{
var helloWorldText = L("HelloWorld"); //...
}
}
You should set LocalizationSourceName to make L method working. You can set it in your own base api controller class, to not repeat for each api controller.
Others
You can also use pre-injected AbpSession, EventBus, PermissionManager, PermissionChecker, SettingManager, FeatureManager, FeatureChecker, LocalizationManager, Logger, CurrentUnitOfWork base properties and more.
Filters
ABP defines some pre-built filters for AspNet Web API. All of them are added to all actions of all controllers by default.
ABP定义了预建的过滤器ASPNET Web API。所有这些都默认添加到所有控制器的所有操作中。
Audit Logging
AbpApiAuditFilter is used to integrate to audit logging system. It logs all requests to all actions by default (if auditing is not disabled). You can control audit logging using Audited and DisableAuditing attributes for actions and controllers.
abpapiauditfilter是用来整合审计日志系统。默认情况下,它将所有请求记录到所有操作(如果没有禁用审核)。你可以控制审计日志审计和disableauditing使用动作和控制器属性。
Authorization
You can use AbpApiAuthorize attribute for your api controllers or actions to prevent unauthorized users to use your controllers and actions. Example:
你可以使用abpapiauthorize属性为你的API控制器或行动来防止未经授权的用户使用你的控制器和动作。例子:
public class UsersController : AbpApiController
{
[AbpApiAuthorize("MyPermissionName")]
public UserDto Get(long id)
{
//...
}
}
You can define AllowAnonymous attribute for actions or controllers to suppress authentication/authorization. AbpApiController also defines IsGranted method as a shortcut to check permissions in the code.
你可以定义为行动或控制器来抑制认证/授权allowanonymous属性。AbpApiController还定义了权限法作为一种快捷方式来检查代码的权限。
See authorization documentation for more.
Anti Forgery Filter(防伪过滤器)
AbpAntiForgeryApiFilter is used to auto protect ASP.NET Web API actions (including dynamic web api) for POST, PUT and DELETE requests from CSRF/XSRF attacks. See CSRF documentation for more.
abpantiforgeryapifilter用于自动保护ASP.NET Web API的行为(包括动态Web API)后,将删除CSRF / XSRF攻击的请求。更看CSRF的文档。
Unit Of Work
AbpApiUowFilter is used to integrate to Unit of Work system. It automatically begins a new unit of work before an action execution and completes unit of work after action exucition (if no exception is thrown).
You can use UnitOfWork attribute to control behaviour of UOW for an action. You can also use startup configuration to change default unit of work attribute for all actions.
abpapiuowfilter是用来整合的工作系统。它会自动开始一个新的工作单位前一个动作的执行和完成行动后exucition工作单位(如果没有抛出异常)。
你可以使用属性来控制一个动作UnitOfWork UOW的行为。还可以使用启动配置更改所有操作的默认工作单元属性。
Result Wrapping & Exception Handling(结果包装和异常处理)
ASP.NET Boilerplate does not wrap Web API actions by default if action has successfully executed. But it handles and wraps for exceptions. You can add WrapResult/DontWrapResult to actions and controllers if you need. You can change this default behaviour from startup configuration (using Configuration.Modules.AbpWebApi()...). See AJAX document for more about result wrapping.
ASP.NET样板不包Web API的行为默认如果行动已成功执行。但是它处理和包装异常。您可以添加wrapresult / dontwrapresult行动和控制器,如果你需要。您可以更改此默认行为的启动配置(使用配置模块。abpwebapi()…)。有关结果包装的更多内容,请参见Ajax文档。
Result Caching(结果缓存)
ASP.NET Boilerplate adds Cache-Control header (no-cache, no-store) to the response for Web API requests. Thus, it prevents browser caching of responses even for GET requests. This behaviour can be disabled by the configuration.
ASP.NET的模板添加缓存控制头(没有缓存,没有存储)的响应的Web API请求。因此,即使GET请求,它也阻止浏览器缓存响应。可以通过配置禁用此行为。
Validation
AbpApiValidationFilter automatically checks ModelState.IsValid and prevents execution of the action if it's not valid. Also, implements input DTO validation described in the validation documentation.
abpapivalidationfilter modelstate.isvalid防止自动检查和执行行动,如果它不是有效的。因此,输入验证工具验证文件中描述的DTO的。
Model Binders(模型绑定)
AbpApiDateTimeBinder is used to normalize DateTime (and Nullable<DateTime>) inputs using Clock.Normalize method.
ABP框架系列之五十三:(Web-API-Controllers-Web-API-控制器)的更多相关文章
- ABP框架系列之三十三:(Module-System-模块系统)
Introduction ASP.NET Boilerplate provides an infrastructure to build modules and compose them to cre ...
- ABP框架系列之十三:(Authorization-授权)
Introduction Almost all enterprise applications use authorization in some level. Authorization is us ...
- ABP框架系列之五十四:(XSRF-CSRF-Protection-跨站请求伪造保护)
Introduction "Cross-Site Request Forgery (CSRF) is a type of attack that occurs when a maliciou ...
- ABP框架系列之五:(Unit Of Work-工作单元)
Introduction Connection and transaction management is one of the most important concepts in an appli ...
- ABP框架系列之五十:(Swagger-UI-集成)
Introduction From it's web site: "....with a Swagger-enabled API, you get interactive documenta ...
- ABP框架系列之五十二:(Validating-Data-Transfer-Objects-验证数据传输对象)
Introduction to validation Inputs of an application should be validated first. This input can be sen ...
- ABP框架系列之四十三:(OData-Integration-OData集成)
Introduction OData is defined as "An open protocol to allow the creation and consumption of que ...
- ABP框架系列之五十一:(Timing-定时)
Introduction While some applications target a single timezone, some others target to many different ...
- 老周的ABP框架系列教程 -》 一、框架理论初步学习
老周的ABP框架系列教程 -- 一.框架理论初步学习 1. ABP框架的来源与作用简介 1.1 简介 1.1.1 ABP框架全称为"ASP.NET Boilerplate ...
随机推荐
- ssh免密钥之上厕所
ssh服务简单介绍 SSH协议框架中最主要的部分是三个协议: *传输层协议(The Transport Layer Protocol)提供服务器认证,数据机密性,信息完整性等的支持; *用户认证协议( ...
- npm安装与使用
NPM 使用介绍 摘自:http://www.runoob.com/nodejs/nodejs-npm.html NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题, ...
- The perception and large margin classifiers
假设样例按照到来的先后顺序依次定义为.为样本特征,为类别标签.任务是到来一个样例,给出其类别结果的预测值,之后我们会看到真实值,然后根据真实值来重新调整模型参数,整个过程是重复迭代的过程,直到所有的样 ...
- 残差神经网络与inception-resnet
一.基本概念 Residual Connection: 本质是“短路连接” 如下图阴影部分,通过增加shortcuts,加速训练,从而可以训练出更深的模型(I.R.v2 > Inception ...
- Xilinx------BUFG,IBUFG,BUFGP,IBUFGDS等含义以及使用
转载-----BUFG,IBUFG,BUFGP,IBUFGDS等含义以及使用 目前,大型设计一般推荐使用同步时序电路.同步时序电路基于时钟触发沿设计,对时钟的周期.占空比.延时和抖动提出了更高的要 ...
- vue+窗格切换+田字+dicom显示_01
环境:vue+webpack+cornerstone ide:vs code 需求:窗格设置+拼图设置 1.点击左边第一个窗格或者默认显示. 2.点击第二个也同理显示,以此类推 3.选择左边的窗格之后 ...
- day28元类与异常查找
元类与异常处理1. 什么是异常处理 异常是错误发生的信号,一旦程序出错就会产生一个异常,如果该异常 没有被应用程序处理,那么该异常就会抛出来,程序的执行也随之终止 异常包含三个部分: ...
- 关于Haclon使用GPU加速的代码实例
关于Haclon使用GPU加速的代码实例 read_image(Image, 'T20170902014819_58_2_1.bmp') *没有加加速并行处理 count_seconds(T1) to ...
- .NET MVC 过滤器使用
来看以下两种情况 1. 如果我们需要对某个模块做权限控制,通常的做法是写一个基类(BaseController),让这个基类继承Controller类,在BaseController的构造方法中进行权 ...
- Ubuntu输入命令无效的问题
https://blog.csdn.net/u014797226/article/details/80800550?utm_source=blogxgwz2 Ubuntu启动时输入密码后,一直停留在登 ...