ABP框架系列之三十五:(MVC-Controllers-MVC控制器)

Introduction

ASP.NET Boilerplate is integrated to ASP.NET MVC Controllers via Abp.Web.Mvc nuget package. You can create regular MVC Controllers as you always do. Dependency Injection properly works for regular MVC Controllers. But you should derive your controllers from AbpController, which provides several benefits and better integrates to ASP.NET Boilerplate.

ASP.NET样板集成到ASP.NET的MVC控制器通过abp.web.mvc NuGet包。您可以像平常一样创建常规的MVC控制器。依赖注入适用于常规MVC控制器。但是你应该得到你abpcontroller控制器,它提供了几个好处,更好的融入到ASP.NET样板。

AbpController Base Class

This is a simple controller derived from AbpController:

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

AbpController defines L method to make localization easier. Example:

public class HomeController : AbpController
{
    public HomeController()
    {
        LocalizationSourceName = "MySourceName";
    }

    public ActionResult Index()
    {
        var helloWorldText = L("HelloWorld");

        return View();
    }
}

You should set LocalizationSourceName to make L method working. You can set it in your own base controller class, to not repeat for each controller.

Others

You can also use pre-injected AbpSession, EventBus, PermissionManager, PermissionChecker, SettingManager, FeatureManager, FeatureChecker, LocalizationManager, Logger, CurrentUnitOfWork base properties and more.

Filters

Exception Handling & Result Wrapping(异常处理与结果包装

All exceptions are automatically handled, logged and a proper response is returned to the client. See exception handling documentation for more.

所有异常都会自动处理、记录,并将适当的响应返回给客户机。查看更多的异常处理文档。

ASP.NET Boilerplate also wraps action results by default if return type is JsonResult (or Task<JsonResult> for async actions).

You can change exception handling and wrapping by using WrapResult and DontWrapResult attributes for controllers or actions or from startup configuration (using Configuration.Modules.AbpMvc()...) globally. See ajax documentation for more.

你可以改变的异常处理和包装用的启动配置控制器或动作或wrapresult和dontwrapresult属性(使用配置模块。abpmvc())。更多的见ajax文档。

Audit Logging(审计日志
AbpMvcAuditFilter 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.
abpmvcauditfilter是用来整合审计日志系统。默认情况下,它将所有请求记录到所有操作(如果没有禁用审核)。你可以控制审计日志审计和disableauditing使用动作和控制器属性。
Validation

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

Authorization

You can use AbpMvcAuthorize attribute for your controllers or actions to prevent unauthorized users to use your controllers and actions. Example:

public class HomeController : AbpController
{
    [AbpMvcAuthorize("MyPermissionName")]
    public ActionResult Index()
    {
        return View();
    }
}

You can define AllowAnonymous attribute for actions or controllers to suppress authentication/authorization. AbpController also defines IsGranted method as a shortcut to check permissions.

See authorization documentation for more.

Unit Of Work

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

Anti Forgery(防伪

AbpAntiForgeryMvcFilter is used to auto protect MVC actions for POST, PUT and DELETE requests from CSRF/XSRF attacks. See CSRF documentation for more.

Model Binders

AbpMvcDateTimeBinder is used to normalize DateTime (and Nullable<DateTime>) inputs using Clock.Normalize method.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值