.NET7的第三个预览版发布了,同样带来了mini api的更新,这次带来了路由过滤器,与mvc版的action 过滤器相似。具体见(string no) =>{ Console.WriteLine($"Get方法中:no={no}"); return new Data { No = no, Name = "test" + DateTime.Now };}).AddFilter((RouteHandlerInvocationContext context, RouteHandlerFilterDelegate next) => { var no = (string?)context.Parameters[0]; Console.WriteLine($"Get方法前:no={no}"); if (no != null && !no.StartsWith("NO")) { return new ValueTask
var builder = WebApplication.CreateBuilder(args);var app = builder.Build();Data GetData(string no){ Console.WriteLine($"Get方法中:no={no}"); return new Data { No = no, Name = "test" + DateTime.Now };};//第一种方式app.MapGet("/data1/{no}", GetData) .AddFilter((RouteHandlerInvocationContext context, RouteHandlerFilterDelegate next) => { var no = (string?)context.Parameters[0]; Console.WriteLine($"Get方法前:no={no}"); if (no != null && !no.StartsWith("NO")) { return new ValueTask
暂时没有评论,来抢沙发吧~