我正在尝试为位于Docker上的api服务器部署Hangfire仪表板。在本地,当我运行https://localhost:1234/hangfire时,页面会正确显示。然而,一旦它坐在码头上,出于某种原因,它只显示404。
这是我的startup.cs
public void Services(IServiceCollection services, string connstr)
{
var mysqlOptions = new MySqlStorageOptions
{
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
QueuePollInterval = TimeSpan.FromSeconds(15),
JobExpirationCheckInterval = TimeSpan.FromHours(1),
CountersAggregateInterval = TimeSpan.FromMinutes(5),
PrepareSchemaIfNecessary = true,
DashboardJobListLimit = 50000,
TransactionTimeout = TimeSpan.FromMinutes(1),
//TablesPrefix = "Hangfire"
};
services.AddHangfire(x => {
x.UseStorage(new MySqlStorage(connstr, mysqlOptions));
});
services.AddHangfireServer();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error/500");
app.UseHsts();
}
LoadConfigurationServices loadConfigurationServices = new LoadConfigurationServices();
loadConfigurationServices.Configure(app, env);
var staticFileCacheInSeconds = configuration[SDR_Core.ClassLibrary.Globals.ConfigurationGlobals.StaticFileCacheInSeconds];
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx => {
int durationInSeconds = Int32.Parse(staticFileCacheInSeconds);
ctx.Context.Response.Headers[HeaderNames.CacheControl] =
"public,max-age=" + durationInSeconds;
}
});
var culture = configuration[SDR_Core.ClassLibrary.Globals.ConfigurationGlobals.Culture];
LoadCultureServices loadCultureServices = new LoadCultureServices();
loadCultureServices.Configure(culture);
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints((config) =>
{
config.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{Controller=Home}/{Action=Index}/{id?}");
config.MapControllerRoute(
name: "default",
pattern: "{Controller=Home}/{Action=Index}/{id?}");
config.MapRazorPages();
});
app.UseHangfireDashboard("/hangfire");
app.UseCookiePolicy();
}在码头,我的网址是http://localhost:1234/hangfire
发布于 2022-06-09 12:05:44
我在下面的提示中找到,我知道我们可以访问本地的仪表板页面。
默认情况下,授权配置所需的允许只对本地请求访问仪表板页面。为了给生产使用提供适当的权利,请参阅配置授权部分。
因此,您可以参考官方文章来实现它。
https://stackoverflow.com/questions/72476462
复制相似问题