Document Directory
The content of this section:
- Brief introduction
- Abpapicontroller base class
- Filter
- Audit log
- Authorized
- Anti-Counterfeiting Filter
- Unit of work
- Result wrapping and Exception handling
- Result Cache
- Verify
- Module Binder
Brief introduction
The ABP is integrated into the ASP. NET WEB Api controller through the ABP.WEB.API NuGet package. You can create the usual ASP. NET WEB API controller as you did before, dependency injection will work well for these ordinary apicontroller, but you will inherit your controller from Abpapicontroller, which provides many benefits and better integration into the ABP.
Abpapicontroller base class
This is a simple API controller that inherits from the Abpapicontroller:
Public class abpapicontroller{}
Localization
Abpapicontroller defines the L method, which makes localization easier, such as:
Public classUserscontroller: abpapicontroller{ PublicUserscontroller () { localizationsourcename = "mysourcename" ; } PublicUserdto Get (LongID) {varHelloworldtext =L ("HelloWorld" ); //... }}
You have to set the Localizationsourcename,l method to work correctly, you can set it up in your own base API controller class so that you don't have to repeat the setup for each API controller.
Other
You can use pre-injected abpsession, Eventbus, Permissionmanager, PermissionChecker, Settingmanager, FeatureManager, Featurechecker , Localizationmanager, Logger, Currentunitofwork, and other base properties.
Filter
The ABP presets Some filtering for all ASP. NET Web APIs, which are added by default to all actions of all controllers.
Audit log
Abpapiauditfilter is used to integrate into the audit log system, which records all action requests by default (if the audit is not disabled), you can use the audited and disableauditing features to control audit logs for the action and controller.
Authorized
You use the Abpapiauthorize feature for your API controller or action to prevent unauthorized users from accessing them, for example:
Public class userscontroller:abpapicontroller{ [Abpapiauthorize ("mypermissionname ")]public userdto Get (long id) { //... }}
You can define the AllowAnonymous feature for action or controller, and revoke authentication/authorization. Abpapicontroller also defines a quick way to check permissions in a definition isgranted.
See the licensing documentation for more information.
Anti-Counterfeiting Filter
Abpantiforgeryapifilter automatically protects the ASP. NET Web API's action, including the dynamic Web API, from Csrf/xsrf Post, put, and delete request attacks. See the CSRF documentation for more information.
Unit of work
Abpapiuowfilter is used to integrate into a unit of work system, automatically starting a unit of work before an action executes, and completing the unit of work (if no exception is thrown) after the action execution finishes.
You can use the Unitofwork feature for an action to control its work cell behavior, or you can modify the default unit of work properties for all actions in the launch configuration.
Result wrapping and Exception handling
When the action of the Web API is executed successfully, the ABP does not automatically wrap it by default, but the ABP handles and wraps the exception, and if necessary, you can add wrapresult/dontwrapresult to the action and controller, You can modify this default behavior from the boot configuration (using Configuration.Modules.AbpWebApi () .... )。 For more information about the resulting wrapper, view the AJAX documentation.
Result Cache
The ABP adds a Cache-control header (No-cache,no-store) to the Web API request response, so it even prevents the browser from caching the GET request response, but can be configured by configuring this behavior.
Verify
Abpapivalidationfilter automatically checks for modelstate.isvalid and blocks action execution when illegal is detected. Validation of the input dto is described in the validation document.
Module Binder
The Abpapidatetimebinder is used to standardize DateTime (and nullable<datetime>) inputs through the Clock.normalize method.
<<ABP documentation >> WEB API Controller