.net core 过滤器

出处: https://www.cnblogs.com/intotf/p/10189665.html

 

     app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            //添加根目录下的  UpdataFiles目录可以防问
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "UpdataFiles")),
                RequestPath = new PathString("/UpdataFiles")
            });

            //添加(wwwroot目录下的)静态文件夹防问   如文件夹下的 js css  图片
            app.UseStaticFiles();

 

    public class FilterController : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            //拦截全局里是否带了token
            if (string.IsNullOrEmpty(context.HttpContext.Request.Query["token"]))
            {
               
            }

        }
    }
      public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddMvc(options =>
            {
                //options.Filters.Add<XXXActionFilter>();
                options.Filters.Add<FilterController>();
            });
            
        }

 

posted @ 2019-10-25 16:42  enych  阅读(277)  评论(0编辑  收藏  举报