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 ...
随机推荐
- HTTPS如何保证数据传输的安全性 -- 结合加密
什么是HTTPS: HTTP就是我们平时浏览网页时候使用的一种协议 HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不安全.为了保证这些隐私数据能加密传输,于是网 ...
- Hibernate一对多OnetoMany
------------------------Hibernate一对多OnetoMany 要点: 配置在一端. 1.如果是单向关联,即只在一端配置OneToMany,多端不配置ManyToOne.则 ...
- kickstart之中rootpw密码生成方法
一.简介 linux kickstart文件里rootpw密码可以使用明文,也可以使用加密过的值,这里主要介绍下三种加密方法:md5.sha256.sha512 使用明文的方法 rootpw &quo ...
- jquery中live is not a function的问题
jquery中的live()方法在jquery1.9及以上的版本中已被废弃了,如果使用,会抛出TypeError: $(...).live is not a function错误. 解决方法: 之前的 ...
- Laravel线上布暑到linux的问题汇总
1.直接报403错误 ,配置文件中增加: location / { try_files $uri $uri/ /index.php?$query_string; } 同时根目录不是指到项目名,而是指到 ...
- tensorflow-yolo3系列配置文章汇总
yolo 网络讲解 https://blog.csdn.net/m0_37192554/article/details/81092514 https://blog.csdn.net/guleileo/ ...
- 一份快速完整的Tensorflow模型保存和恢复教程(译)(转载)
该文章转自https://blog.csdn.net/sinat_34474705/article/details/78995196 我在进行图像识别使用ckpt文件预测的时候,这个文章给我提供了极大 ...
- scp: command not found
scp 不能用? [root@doc]# scp jdk-8u144-linux-x64.tar.gz root@10.10.10.17:/root/ root@10.10.10.17's passw ...
- BASEDIR
1)正常写python程序会有一个可执行的bin.py文件,假如这个文件需要导入my_module里面定义的模块,应该怎么设置sys.path(此时可以直接导入), 因为bin和model属于同级目录 ...
- SpringBoot +Pom.xml工程资源文件配置
继承spring-boot-starter-parent 要成为一个spring boot项目,首先就必须在pom.xml中继承spring-boot-starter-parent,同时指定其版本 & ...