在客户环境中部署了包括hangfire UI的应用程序后,我们注意到hangfire UI无法正常工作。后端(也公开用于测试的hangfire UI)的URL为https://root/services/app-api。
我们使用以下命令注册hangfire用户界面:
public static void UseHangfireDashboard(this IAppBuilder app, bool enableForLocalhost, string enabledAppRoleNames)
{
var authorizationFilters = new List<IDashboardAuthorizationFilter>();
if (enableForLocalhost)
{
authorizationFilters.Add(new LocalRequestsOnlyAuthorizationFilter());
}
if (!string.IsNullOrWhiteSpace(enabledAppRoleNames))
{
string[] authorizedRoleNames = enabledAppRoleNames.Split(new[] { ROLES_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries)
.Select(appRole => appRole.Trim())
.ToArray();
authorizationFilters.Add(new HangfireDashboardAuthorizeByAppRoleNamesFilter(authorizedRoleNames));
}
app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = authorizationFilters });
}
因此可以在https://root/services/app-api/hangfire上访问hangfire UI
但是它无法加载所需的css和js文件,因为它试图从https://root/hangfire/获取它们。由于相同的原因,所有链接也被破坏了。
我一直无法弄清楚如何告诉hangfire使用正确的URL。
我检查了以下链接:
https://discuss.hangfire.io/t/dashboard-url-issues-when-deployed-below-site-root/598
http://source.technology/hangfire-authentication
-VirtualPathUtility.ToAbsolute(VirtualPathUtility.ToAbsolute(“〜/ hangfire”)):System.Web.HttpException:'由于相对于应用程序的路径未知,无法将应用程序相对虚拟路径'〜/ hangfire'设为绝对。
-尝试设置用于测试目的的绝对路径(app.UseHangfireDashboard("http://<absolutePath>/hangfire", new DashboardOptions { Authorization = authorizationFilters }
)时,出现System.ArgumentException:'路径必须以'/'开头,后跟一个或多个字符。'