从Visual Studio 2019 React模板项目访问HangFire端点



按照https://medium.com/@jamesdale1993/asp-net-core-2-with-signar-and-react-redux-a-imple-example-c25ea6b19dbe我用Visual Studio 2019和react-redux模板(core 3.0项目(创建了一个项目。

我按照文章的要求启动并运行了SignalR,并在后端代码中将前端连接到SignalR端点。

然后我安装了HangFire(https://www.hangfire.io/),设置它,并且为测试设置的重复作业正常工作。我可以看到(在数据库中(重复出现的作业每分钟都在正常工作。

我的问题:我无法访问HangFire Dashboard!默认情况下,它应该是http://localhost:55663/hangfire,但我只看到模板项目的标题。

我想这是某种路由问题,因为我只能访问ClientApp/build文件夹中提供的内容(react(。

如有任何帮助,我们将不胜感激。

我尝试通过设置应用程序。UseHangfireDashboard("/jobs"(;在Startup.cs配置部分,结果相同。

在下面的Startup.cs代码中,搜索相关部分的"Hangfire"。

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
services.AddControllersWithViews();
// In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/build";
});
services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));
// Database connection
services.AddTransient<IDbConnection>((sp) =>
new SqlConnection(Configuration.GetConnectionString("TestProjectConnection"))
);
// Hangfire
services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("TestProjectConnection")));
services.AddHangfireServer();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
[System.Obsolete]
public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseCors("MyPolicy");
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseRouting();
//Hangfire endpoint
app.UseHangfireDashboard("/jobs");
//backgroundJobs.Enqueue(() => Debug.WriteLine("Hello world from Hangfire!"));
RecurringJob.AddOrUpdate<ITestClass>("TestMethod", x => x.WriteMessage("Testing"), Cron.MinuteInterval(1));
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
app.UseSignalR(routes =>
{
routes.MapHub<SignalRCounter>("/signalrcounter");
});

app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp/build";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});

}

这是路线顺序的问题。

使用:

public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseCors("MyPolicy");
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSignalR(routes =>
{
routes.MapHub<SignalRCounter>("/signalrcounter");
});

app.UseHangfireDashboard("/hangfire");
app.UseRewriter();
app.UseAuthentication();
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp/build";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
app.UseHangfireServer();
//backgroundJobs.Enqueue(() => Debug.WriteLine("Hello world from Hangfire!"));
RecurringJob.AddOrUpdate<ITestClass>("TestMethod", x => x.WriteMessage("Testing"), Cron.MinuteInterval(1));
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
}

相关内容

  • 没有找到相关文章

最新更新