1 .Netcore ExceptionFilter 即使是全局的,也只能抓取controller 的异常,不能抓取 中间件 的异常,
Filter 只对controller起作用。
AuthorizationFilter 可以修饰Controller 或action . 或放在全局,这里的授权,也只是对controller 而言的。
在Action 发生了异常,还会接着执行ActionExecuted(). 再进入ExceptionFilter. 就是说相当于ExceptionFilter 在最外层进行了包裹
之后中间件会依次倒序执行回去。发生异常,并不会跳出整个中间件流程。
然后会进入下一个
2 进程内 进程外
进程指的是IIS worker Process, 就是IIS 进程。
如果是进程内,整个 .netcore 进程是包裹在IIS 中的。IIS 需要安装一个模块,就是windows-hosting-bundle-installer
3. ASP.NET Core Module 做了什么?
只和 Kestrel 配合使用
可以做设置环境变量,设置Log,设置Windows 认证,这些是在Web.config 中设置的。Kestrel 不需要这个配置文件。还可以做app_offline.htm file 停止III的功能
4.在ABP等框架中,Action 里面直接用依赖注入的IResposity<> 接口,然后 add(), Update(), 没有SaveChanges(),就可以保存。怎么做到的呢?
加入这个样的Filter 就可以了。使用了MyDBContext 是Scope 作用域的特性。 代码:
public class MySampleActionFilter : IActionFilter { MyDBContext _context; public MySampleActionFilter (MyDBContext context) { _context=context; } public void OnActionExecuting(ActionExecutingContext context) {// Do something before the action executes. MyDebug.Write(MethodBase.GetCurrentMethod(), context.HttpContext.Request.Path); } public void OnActionExecuted(ActionExecutedContext context) {
_context.SAveChanges();
}
}