我的环境是 .net 5.0 在 但是应该是所有版本的 CrystalQuartz 都通用这个思路.
public static class ApplicationBuilderExtensions { public static void UseCrystalQuartzAuthenticate( this IApplicationBuilder app, Func<object> schedulerProvider, CrystalQuartzOptions options) { ISchedulerProvider provider = new FuncSchedulerProvider(schedulerProvider); CrystalQuartzOptions actualOptions = options ?? new CrystalQuartzOptions(); string text = actualOptions.Path ?? "/quartz"; var optionsVal = new Options(actualOptions.TimelineSpan, SchedulerEngineProviders.SchedulerEngineResolvers, actualOptions.LazyInit, actualOptions.CustomCssUrl, ".net 5"); EndpointRoutingApplicationBuilderExtensions.UseEndpoints(app, routes => { // 新增一个 app RunningApplication runningApplication = new CrystalQuartzPanelApplication(provider, optionsVal).Run(); routes.Map(text, async delegate (HttpContext httpContext) { AuthenticateResult authenticate = await AuthenticationHttpContextExtensions.AuthenticateAsync(httpContext); IRequest request = new AspNetCoreRequest(httpContext.Request.Query, httpContext.Request.HasFormContentType ? httpContext.Request.Form : null); IResponseRenderer responseRenderer = new AspNetCoreResponseRenderer(httpContext); if (authenticate.Succeeded) { runningApplication.Handle(request, responseRenderer); } else { responseRenderer.Render(new Response("text/html", 200, p => { p.Write(System.Text.Encoding.UTF8.GetBytes("no login")); })); } }); }); } }
app.UseCrystalQuartz 替换成我们自己的 app.UseCrystalQuartzAuthenticate
原理就是修改中间件,把他的中间件换成我们自己写的,在数据处理之前校验下身份信息.
也可以简单点,直接弄个控制器,
记录完毕,主要给自己看,如果能对你也有帮助,那也是极好的~