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.
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.
ABP框架系列之三十五:(MVC-Controllers-MVC控制器)的更多相关文章
- ABP框架系列之三十二:(Logging-登录)
Server Side(服务端) ASP.NET Boilerplate uses Castle Windsor's logging facility. It can work with differ ...
- ABP框架系列之三十四:(Multi-Tenancy-多租户)
What Is Multi Tenancy? "Software Multitenancy refers to a software architecture in which a sing ...
- ABP框架系列之三十九:(NLayer-Architecture-多层架构)
Introduction Layering of an application's codebase is a widely accepted technique to help reduce com ...
- ABP框架系列之三十六:(MVC-Views-MVC视图)
Introduction ASP.NET Boilerplate is integrated to MVC Views via Abp.Web.Mvc nuget package. You can c ...
- ABP框架系列之三十八:(NHibernate-Integration-NHibernate-集成)
ASP.NET Boilerplate can work with any O/RM framework. It has built-in integration with NHibernate. T ...
- ABP框架系列之十五:(Caching-缓存)
Introduction ASP.NET Boilerplate provides an abstraction for caching. It internally uses this cache ...
- ABP框架系列之四十五:(Quartz-Integration-Quartz-集成)
Introduction Quartz is a is a full-featured, open source job scheduling system that can be used from ...
- ABP框架系列之三十:(Javascript-API-Javascript-API)
ASP.NET Boilerplate provides a set of objects and functions that are used to make javascript develop ...
- ABP框架系列之五十四:(XSRF-CSRF-Protection-跨站请求伪造保护)
Introduction "Cross-Site Request Forgery (CSRF) is a type of attack that occurs when a maliciou ...
随机推荐
- zeal工具的安装与使用(离线api文档浏览器)
本来想下载一个dash来用一下,结果它只有mac版本,没有windows版,遂使用zeal zeal官网:https://zealdocs.org/ 文档地址:http://kapeli.com/do ...
- 在pycharm_2018.2版本中开启Flask的debug的方法 (不要用命令:python **.py启动)
断点后,先ctl+c关闭控制台程序,再点击debuger调试 问题描述:在pycharm_2018.2版本中,我明确开启了debug,代码如下所示: from flask import Flask a ...
- springboot整合mybatis之注解方式
1. 创建maven项目,工程目录如下图 2. 在pom.xml文件中添加mybatis依赖. 3. 创建实体类,并生成construct方法,getter和setter方法.同时在数据库中创建对应的 ...
- MySQL 之 MHA + ProxySQL + keepalived 实现读写分离,高可用(一)
准备服务器: docker network create --subnet=192.168.0.0/16 staticnetdocker run -d --privileged -v `pwd`/my ...
- tfs项目管理
同一个地址下有多个项目,但同一个文件只能映射一次.有两种方式: 1.只添加一次映射,即只给根目录添加映射,如下图,这样西面的具体的项目就不需要挨个添加了. . 2.每个项目挨个添加映射,使用这种方式要 ...
- java中的静态变量、静态方法与静态代码块详解与初始化顺序
我们知道类的生命周期分为装载.连接.初始化.使用和卸载的五个过程.其中静态代码在类的初始化阶段被初始化. 而非静态代码则在类的使用阶段(也就是实例化一个类的时候)才会被初始化. 静态变量 可以将静 ...
- List接口、Set接口和Map接口
1.List和Set接口继承自Collection接口,而Map不是继承的Collection接口 Map没有继承Collection接口,Map提供key到value的映射;一个Map中不能包含相同 ...
- Redis管理:安全/耗时命令日志与命令监控/数据库管理工具
1.安全管理 1)绑定指定IP Redis的安全设计是在“Redis运行在可信环境”这个前提之下的,在生产环境中建议通过应用程序连接Redis.Redis可以配置只接受来自指定IP的的请求,可通过修改 ...
- Windows操作系统的版本
Windows操作系统的版本号一览 操作系统 PlatformID 主版本号 副版本号 Windows95 1 4 0 Windows98 1 4 10 WindowsMe 1 4 90 Window ...
- spark java.lang.OutOfMemoryError: unable to create new native thread
最近迁移集群,在hadoop-2.8.4 的yarn上跑 spark 程序 报了以下错误 java.lang.OutOfMemoryError: unable to create new native ...