<<ABP Documentation >> MVC Controller

Source: Internet
Author: User

Document Directory

The content of this section:

    • Brief introduction
    • Abpcontroller base class
      • Localization
      • Other
    • Filter
      • exception handling and result wrapping
      • Audit log
      • Verify
      • Authorized
      • Unit of work
      • Anti-counterfeiting
    • Model Binder

Brief introduction

The ABP is integrated into the ASP. NET MVC controller via NuGet package ABP.WEB.MVC. You can create a normal MVC controller as usual, and dependency injection can work on a common MVC controller, but you should make your control inherit from Abpcontroller, which provides many benefits and better integration into the ABP.

Abpcontroller base class

This is a simple controller that inherits from Abpcontroller:

 Public class  abpcontroller{    public  actionresult Index ()    {        return View ();    }}

Localization

The ABP defines the L method, which makes localization easier, such as:

 Public classhomecontroller:abpcontroller{ PublicHomeController () { localizationsourcename = "mysourcename" ; }     PublicActionResult Index () {varHelloworldtext = L ("HelloWorld"); returnView (); }}

To set up the Localizationsourcename before the L method works, you can set it in your controller base class so that you do not have to repeat the settings for each controller.

Other

You can use pre-injected abpsession, Eventbus, Permissionmanager, PermissionChecker, Settingmanager, FeatureManager, Featurechecker , Localizationmanager, Logger, Currentunitofwork, and other base properties.

Filter

exception handling and result wrapping

All exceptions are processed automatically, logs and returns an adaptive response to the client, with more information to view exception handling.

If the return type of the action is Jsonresult (or asynchronous task<jsonresult>), the ABP will also default to wrapping the result.

You can modify exception handling and result wrapping by giving the controller or action the Wrapresult and Dontwrapresult features, or in the boot configuration (using CONFIGURATION.MODULES.ABPMVC () ... ) for global settings. See Ajax documentation for more information.

Audit log

Abpmvcauditfilter 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.

Verify

Abpmvcvalidationfilter automatically checks for modelstate.isvalid and blocks action execution when illegal is detected. Validation of the input dto is described in the validation document.

Authorized

You can use the Abpapiauthorize feature for your API controller or action to prevent unauthorized users from accessing them, for example:

 Public class homecontroller:abpcontroller{    [Abpmvcauthorize ("mypermissionname  ")]public      actionresult Index ()    {          return  View ();}    }

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.

Unit of work

The abpmvcuowfilter 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.

Anti-counterfeiting

Abpantiforgerymvcfilter automatically protects the MVC action, blocking post, put, and delete request attacks from CSRF/XSRF. See the CSRF documentation for more information.

Module Binder

The Abpmvcdatetimebinder is used to standardize DateTime (and nullable<datetime>) inputs through the Clock.normalize method.

<<ABP Documentation >> MVC Controller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.