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 ...
随机推荐
- 高性能mysql 第六章查询性能优化 总结(上)查询的执行过程
6 查询性能优化 6.1为什么查询会变慢 这里说明了的查询执行周期,从客户端到服务器端,服务器端解析,优化器生成执行计划,执行(可以细分,大体过程可以通过show profile查看),从服务器端返 ...
- Northwind数据库练习及参考答案
--查询订购日期在1996年7月1日至1996年7月15日之间的订单的订购日期.订单ID.客户ID和雇员ID等字段的值 Create View Orderquery as Select OrderDa ...
- 学习excel的使用技巧四显示正常的数字
记得之前在excel中输入一些数字比如输入手机号 就会变成1.E几类似这种 那么怎样显示正常的数字呢 先选中要操作的输入框 1 找到 数字 这个功能的地方 2 设置为 数值 并且小数点为0 3 ...
- 面试回顾——session相关
原地址:https://blog.csdn.net/quiet_girl/article/details/50580095 Session结束生命周期的几种情况: (1)客户端关闭浏览器(只针对ses ...
- mysql 乐观锁实现
一.为什么需要锁(并发控制)? 在多用户环境中,在同一时间可能会有多个用户更新相同的记录,这会产生冲突.这就是著名的并发性问题. 典型的冲突有: 1.丢失更新:一个事 ...
- vsCode关闭代码检查工具
在script标签里,第一行输入下面的内容即可:
- 使用wireshark以及filddler配合抓去手机端的TCP以及HTTP请求
在测试手机客户端时,有时候需要查看网络请求状况.使用在IDE中查看log的方式,能够解决问题,但是会比较复杂.wireshark不能够做代理,而fiddler主要是抓HTTP请求,没有wireshar ...
- [INet] WebSocket 数据收发的详细过程
WebSocket 和 HTTP 相似,只是一个应用层协议,对下层透明,所以不涉及 TCP/IP. 由于浏览器支持了 WebSocket,所以在用 JS 写客户端的时候,是无需考虑数据的编码解码的. ...
- 吴裕雄 python深度学习与实践(11)
import numpy as np from matplotlib import pyplot as plt A = np.array([[5],[4]]) C = np.array([[4],[6 ...
- java实现两个不同list对象合并后并排序
工作上遇到一个要求两个不同list对象合并后并排序1.问题描述从数据库中查询两张表的当天数据,并对这两张表的数据,进行合并,然后根据时间排序.2.思路从数据库中查询到的数据放到各自list中,先遍历两 ...