& Lt; ABP document & gt; Mvc controller, abp document mvc Controller

Source: Internet
Author: User

<ABP document> Mvc controller and abp document mvc Controller

Document directory

 

Content of this section:

  • Introduction
  • AbpController base class
    • Localization
    • Others
  • Filter
    • Exception Handling and result Packaging
    • Audit Log
    • Verify
    • Authorization
    • Work Unit
    • Anti-Spoofing
  • Model Binder

 

Introduction

ABC is integrated into the Asp.net Mvc controller through the nuget package ABP. Web. Mvc. You can create a common Mvc controller as usual. Dependency injection can work for a common Mvc controller, but you should inherit your control from AbpController, it provides many benefits and better integration into the ABP.

 

AbpController base class

This is a simple controller inherited from AbpController:

public class HomeController : AbpController{    public ActionResult Index()    {        return View();    }}

 

Localization

ABC defines the L method to make localization easier. For example:

public class HomeController : AbpController{    public HomeController()    {        LocalizationSourceName = "MySourceName";    }    public ActionResult Index()    {        var helloWorldText = L("HelloWorld");        return View();    }}

You must first set LocalizationSourceName to make the L method work normally. You can set it in your controller base class so that you do not need to set it again for each controller.

 

Others

You can use pre-injected basic attributes such as AbpSession, EventBus, PermissionManager, PermissionChecker, SettingManager, FeatureManager, FeatureChecker, LocalizationManager, Logger, CurrentUnitOfWork.

 

Filter

Exception Handling and result Packaging

All exceptions are automatically processed, logs are returned, and an adaptive response is sent to the client. For more information, see exception handling.

If the return type of an Action is JsonResult (or asynchronous Task <JsonResult>), this result is also wrapped by default in the ABP.

You can modify the exception handling and result packaging by using the WrapResult and DontWrapResult features for the Controller or Action, or you can start the Configuration (using Configuration. modules. abpMvc ()...) global settings. For more information, see the ajax document.

 

Audit Log

AbpMvcAuditFilter is used to integrate into the audit log system. It records all Action requests by default (if the audit is not disabled ), you can use the Audited and DisableAuditing features to control the Action and controller audit logs.

 

Verify

AbpMvcValidationFilter automatically checks ModelState. IsValid and stops Action execution when an error is detected. Verification of input DTO is described in the verification document.

 

Authorization

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 the Action or controller to abolish authentication/authorization. AbpApiController also defines an IsGranted shortcut for checking the license in the definition.

For more information, see the authorization document.

 

Work Unit

AbpMvcUowFilter is used to integrate into the work unit system. A work unit is automatically started before an Action is executed, and the work unit is completed after the Action is executed (if no exception is thrown ).

You can use the UnitOfWork feature for an Action to control its unit of work behaviors. You can also modify the default unit of work features for all actions in the startup configuration.

 

Counterfeiting

AbpAntiForgeryMvcFilter automatically protects Mvc actions and prevents POST, PUT, and DELETE request attacks from CSRF/XSRF. For more information, see CSRF documentation.

 

Module Binder

AbpMvcDateTimeBinder is used to standardize the DateTime (and Nullable <DateTime>) input through the Clock. Normalize method ).

Related Article

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.