Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Hangfire授权配置ASP.Net核心应用程序_C#_Asp.net Core_Asp.net Identity_Hangfire_Blazor Webassembly - Fatal编程技术网

C# 使用Hangfire授权配置ASP.Net核心应用程序

C# 使用Hangfire授权配置ASP.Net核心应用程序,c#,asp.net-core,asp.net-identity,hangfire,blazor-webassembly,C#,Asp.net Core,Asp.net Identity,Hangfire,Blazor Webassembly,我有一个ASP.Net核心Blazor WebAssembly应用程序,它正在使用Hangfire。我现在正试图根据文档在生产中使用Hangfire配置授权,但在生产中遇到403错误。 我错过了什么 public void ConfigureServices(IServiceCollection services) { services.AddHttpContextAccessor(); services.AddCors(optio

我有一个ASP.Net核心Blazor WebAssembly应用程序,它正在使用Hangfire。我现在正试图根据文档在生产中使用Hangfire配置授权,但在生产中遇到403错误。 我错过了什么

public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();
            services.AddCors(options =>
            {
                options.AddPolicy(
                    "AllowAny",
                    x =>
                    {
                        x.AllowAnyHeader()
                        .AllowAnyMethod()
                        .SetIsOriginAllowed(isOriginAllowed: _ => true)
                        .AllowCredentials();
                    });
            });
            services.AddOData();
            services.AddODataQueryFilter();
            services.AddDbContext<ApplicationIdentityDbContext>(options =>
            {
                options.UseMySql(Configuration.GetConnectionString("InstaTranscribeDBConnection"));
            });
            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddRoles<IdentityRole>()
                .AddRoleStore<RoleStore<IdentityRole, ApplicationIdentityDbContext, string>>()
                .AddRoleManager<RoleManager<IdentityRole>>()
                .AddDefaultTokenProviders()
                .AddEntityFrameworkStores<ApplicationIdentityDbContext>();
            services.AddIdentityServer().AddApiAuthorization<ApplicationUser, ApplicationIdentityDbContext>();
            services.AddTransient<IdentityServer4.Services.IProfileService, ProfileService>();
            services.AddAuthentication().AddIdentityServerJwt();
            services.AddDbContext<InstaTranscribe.Data.InstaTranscribeDbContext>(options =>
            {
              options.UseMySql(Configuration.GetConnectionString("InstaTranscribeDBConnection"));
            });
            services.AddControllersWithViews();
            services.AddRazorPages();
            #region Add Hangfire services
            var connectionstring=Configuration.GetConnectionString("InstaTranscribeDBConnection");
            var hangfireConnectionstring = $"{connectionstring};Allow User Variables=true";
            var mySqlStorageOptions = new MySqlStorageOptions
            {
              TransactionIsolationLevel = (System.Transactions.IsolationLevel?)IsolationLevel.ReadCommitted,
              QueuePollInterval = TimeSpan.FromSeconds(15),
              JobExpirationCheckInterval = TimeSpan.FromHours(1),
              CountersAggregateInterval = TimeSpan.FromMinutes(5),
              PrepareSchemaIfNecessary = true,
              DashboardJobListLimit = 50000,
              TransactionTimeout = TimeSpan.FromMinutes(1),
              TablesPrefix = "Hangfire"
            };
            var mySqlStorage = new MySqlStorage(hangfireConnectionstring, mySqlStorageOptions);
            services.AddHangfire(config => config.UseStorage(mySqlStorage));
            services.AddHangfireServer();
            #endregion

        }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationIdentityDbContext identityDbContext)
        {
.........code edited for brevity
            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();            
            app.UseRouting();
            app.UseIdentityServer();
            app.UseAuthentication();
            app.UseAuthorization();
            //UseAuthentication, UseAuthorization should be before UseHangfireDashboard
            var dashboardOptions=new DashboardOptions()
            {
              Authorization = new[] { new HangFireJwtAuthorizationFilter() }
            };
            app.UseHangfireDashboard();
            IServiceProvider provider = app.ApplicationServices.GetRequiredService<IServiceProvider>();
            app.UseCors("AllowAny");
            app.UseEndpoints(endpoints =>
            {
.........code edited for brevity
              endpoints.MapHangfireDashboard("/hangfire", dashboardOptions);
            });
        }

public class HangFireJwtAuthorizationFilter : IDashboardAuthorizationFilter
  {
public HangFireJwtAuthorizationFilter()
{
}
public bool Authorize([NotNull] DashboardContext dashboardContext)
{      
  return true;
}
  }
public void配置服务(IServiceCollection服务)
{
AddHttpContextAccessor();
services.AddCors(选项=>
{
options.AddPolicy(
“AllowAny”,
x=>
{
x、 AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed(isOriginAllowed:=>true)
.AllowCredentials();
});
});
services.AddOData();
services.AddODataQueryFilter();

services.AddDbContext

您在ajit goel解决了吗?