当前位置: 首页 > news >正文

专业提供网站制作企业网站备案备注

专业提供网站制作,企业网站备案备注,欧美普货专线是快递吗,wordpress中文是什么?概述通过使用 ASP.NET Core 中的筛选器#xff0c;可在请求处理管道中的特定阶段之前或之后运行代码。内置筛选器处理任务#xff0c;例如#xff1a;授权#xff08;防止用户访问未获授权的资源#xff09;。响应缓存#xff08;对请求管道进行短路出路#xff0c;以便… 概述通过使用 ASP.NET Core 中的筛选器可在请求处理管道中的特定阶段之前或之后运行代码。内置筛选器处理任务例如授权防止用户访问未获授权的资源。响应缓存对请求管道进行短路出路以便返回缓存的响应。可以创建自定义筛选器用于处理横切关注点。 横切关注点的示例包括错误处理、缓存、配置、授权和日志记录。 筛选器可以避免复制代码。 例如错误处理异常筛选器可以合并错误处理。ASP.NET Core Filter如何支持依赖注入?可以通过全局注册支持依赖注入。通过TypeFilter(typeof(Filter)) 标记在方法标记在控制器。通过ServiceType(typeof(Filter))标记在方法标记在控制器必须要注册Filter这类TypeFilter和ServiceType的本质是实现了一个IFilterFactory接口代码实现1、普通Filter使用继承: Attribute, IActionFilter。 public class TestActionFilterAttribute : Attribute, IActionFilter{public void OnActionExecuted(ActionExecutedContext context){if (context.HttpContext.Request.Query.TryGetValue(id, out StringValues value)){Console.WriteLine(value.First());}else{context.HttpContext.Response.Redirect(/Error/404);}}public void OnActionExecuting(ActionExecutingContext context){ }}[TestActionFilter]public IActionResult Index(){return View();} 2、使用  [TypeFilter(typeof(TestActionFilterAttribute))]注入。 public class TestActionFilterAttribute : Attribute, IActionFilter{private readonly ILogger _logger;public TestActionFilterAttribute(ILoggerFactory logger){_logger logger.CreateLogger(TestActionFilterAttribute);}public void OnActionExecuted(ActionExecutedContext context){_logger.LogDebug($11111);if (context.HttpContext.Request.Query.TryGetValue(id, out StringValues value)){Console.WriteLine(value.First());}else{context.HttpContext.Response.Redirect(/Error/404);}}public void OnActionExecuting(ActionExecutingContext context){ }}[TypeFilter(typeof(TestActionFilterAttribute))]public IActionResult Index(){return View();}3、使用 [ServiceFilter(typeof(TestActionFilterAttribute))]注入。 [ServiceFilter(typeof(TestActionFilterAttribute))]public IActionResult Index(){return View();} 运行测试发现报错于是ConfigureServices加上services.AddSingletonTestActionFilterAttribute(); // This method gets called by the runtime. Use this method to add services to the container.public void ConfigureServices(IServiceCollection services){services.AddSingletonTestActionFilterAttribute();services.AddControllersWithViews();} 运行测试成功。4、通过全局注册 public void ConfigureServices(IServiceCollection services){// services.AddSingletonTestActionFilterAttribute();services.AddControllersWithViews(options {// 添加全局异常options.Filters.AddTestActionFilterAttribute();});} 代码地址https://gitee.com/conanOpenSource_admin/service-filter_-type-filter
http://www.sadfv.cn/news/160109/

相关文章:

  • 企业百度网站建设公司网站怎么建
  • 河南省住房与城乡建设厅网站首页软件开发公司
  • 网站设计理念怎么写室内设计手绘图
  • wordpress 导航网站谷歌手机版浏览器官网
  • vs2017网站开发组件网站分屏布局设计
  • 扶贫工作网站建设方案网站引擎友好性分析
  • 什么类型的产品可以做网站出口安卓市场wordpress主题
  • 修改数据库密码 进不了网站后台做产地证的网站
  • 中铁建设工程项目公示网站想学平面设计哪个网上可以学
  • 网站开发的母的目的和意义.服务商是什么意思
  • 制作网站深圳亚马逊云服务器收费标准
  • 网站上的flv视频看不了济南百度seo排名公司
  • 做外贸常用的网站有哪些网页制作与设计软件
  • 百度权重9的网站北京十大室内设计公司排名
  • 有哪些网站是做网批女装浦东新区做网站
  • 济南企业网站制作wordpress自媒体博客模板
  • 哈尔滨自助建站网站需要备案才能建设吗
  • 有没有教做网站实例视频wordpress外链转内链代码
  • 建立网站需要什么条件我要自学网网站建设
  • 成都网站建设行业分析frame wordpress
  • 哈尔滨企业建站服务商王野发动机怎么样
  • 网站开发怎么让别人看到网站规划与开发实训室建设
  • 校园网站建设方案书wordpress好用吗
  • 中山精品网站建设讯息手工活外包加工官方网
  • 国外一些建筑公司网站手机商城网站案例
  • 广州哪里做网站免费个人简历表电子版
  • 电商网站有哪些特色0元代理注册公司
  • 怎么查询一个网站从哪做的企业网站建设公司地址
  • 做网站什么字体比较好看网页设计制作方案
  • 行业门户网站开发中国建设质量协会网站