从 Visual Studio 2019 React 模板项目访问 HangFire 端点
Access HangFire endpoint from Visual Studio 2019 React template project
按照 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,但我只看到模板项目的 header。
我猜这是某种路由问题,因为我只能访问 ClientApp/build 文件夹中提供的内容(反应)。
如有任何帮助,我们将不胜感激。
我尝试通过设置更改默认的 /hangfire 端点
app.UseHangfireDashboard("/职位");在 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?}");
});
}
按照 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,但我只看到模板项目的 header。
我猜这是某种路由问题,因为我只能访问 ClientApp/build 文件夹中提供的内容(反应)。
如有任何帮助,我们将不胜感激。
我尝试通过设置更改默认的 /hangfire 端点 app.UseHangfireDashboard("/职位");在 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?}");
});
}