예제 #1
0
        public static bool IsCanAccessHangfireDashboard(HttpContext httpContext, ElectHangfireOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AccessKey))
            {
                return(true);
            }

            string requestKey = httpContext.Request.Query[AccessKeyName];

            requestKey = string.IsNullOrWhiteSpace(requestKey) ? httpContext.Request.Cookies[CookieAccessKeyName] : requestKey;

            var isCanAccess = options.AccessKey == requestKey;

            return(isCanAccess);
        }
        public static ElectHangfireOptions GetOptions(IConfiguration configuration, string sectionName = "ElectHangfire")
        {
            var electHangfireOptions = new ElectHangfireOptions();

            electHangfireOptions.IsEnable = configuration.GetValueByEnv <bool>($"{sectionName}:{nameof(electHangfireOptions.IsEnable)}");

            electHangfireOptions.Url = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electHangfireOptions.Url)}");

            electHangfireOptions.AccessKey = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electHangfireOptions.AccessKey)}");

            electHangfireOptions.BackToUrl = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electHangfireOptions.BackToUrl)}");

            electHangfireOptions.DbConnectionString = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electHangfireOptions.DbConnectionString)}");

            electHangfireOptions.IsDisableJobDashboard = configuration.GetValueByEnv <bool>($"{sectionName}:{nameof(electHangfireOptions.IsDisableJobDashboard)}");

            electHangfireOptions.Provider = configuration.GetValueByEnv <HangfireProvider>($"{sectionName}:{nameof(electHangfireOptions.Provider)}");

            electHangfireOptions.StatsPollingInterval = configuration.GetValueByEnv <int>($"{sectionName}:{nameof(electHangfireOptions.StatsPollingInterval)}");

            electHangfireOptions.UnAuthorizeMessage = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electHangfireOptions.UnAuthorizeMessage)}");

            return(electHangfireOptions);
        }
예제 #3
0
 public static IServiceCollection AddElectHangfire(this IServiceCollection services, [NotNull] ElectHangfireOptions options)
 {
     return(services.AddElectHangfire(_ =>
     {
         _.Url = options.Url;
         _.AccessKey = options.AccessKey;
         _.BackToUrl = options.BackToUrl;
         _.HangfireDatabaseConnectionString = options.HangfireDatabaseConnectionString;
         _.IsDisableJobDashboard = options.IsDisableJobDashboard;
         _.Provider = options.Provider;
         _.StatsPollingInterval = options.StatsPollingInterval;
         _.UnAuthorizeMessage = options.UnAuthorizeMessage;
         _.ExtendOptions = options.ExtendOptions;
     }));
 }
예제 #4
0
 public ElectHangfireMiddleware(RequestDelegate next, IOptions <ElectHangfireOptions> configuration, RouteCollection routeCollection)
 {
     _next            = next;
     _options         = configuration.Value;
     _routeCollection = routeCollection;
 }