按照https://medium.com/@jamesdale1993/asp-net-core-2-with-signalr-and-react-redux-a-simple-example-c25ea6b19dbe的指南,我使用Visual Studio 2019和react-redux模板创建了一个项目(核心3.0项目)。>>
我按照文章启动并运行了SignalR,在后端代码中响应连接到SignalR端点的前端。
然后我安装了HangFire(https://www.hangfire.io/),进行了设置,并且为测试设置的循环作业正常运行。我可以在数据库中看到每分钟触发一次的定期作业。
我的问题:
我无法访问HangFire信息中心!默认情况下,它应该为http://localhost:55663/hangfire,但我只能看到模板项目的标题。我想这是某种路由问题,因为我只能访问ClientApp / build文件夹中提供的内容(反应)。
任何帮助将不胜感激。
我尝试通过设置来更改默认的/ hangfire端点app.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");
}
});
}
按照该指南在https://medium.com/@jamesdale1993/asp-net-core-2-with-signalr-and-react-redux-a-simple-example-c25ea6b19dbe我使用Visual Studio 2019创建了一个项目和react-redux ...
这是路线的顺序。