asp.net-mvc – 为什么Hangfire需要身份验证才能查看仪表板
我在我的MVC网络应用程序中运行HangFire,但每当我尝试导航到
http://MyApp/hangfire时,它会将我重定向到我的应用程序的登录页面,就好像我没有登录一样.
我没有明确配置任何授权要求……例如.我在web.config中有以下内容,但后来试图让它工作. <location path="hangfire"> <system.web> <authorization> <allow roles="Administrator" /> <deny users="*" /> </authorization> </system.web> 从理论上讲,这就是我想要的,当我登录我的主Web应用程序时,我将以管理员角色登录,因此该规则应该有效. 但是,无论我是否在web.config中配置了它,每当我尝试导航到http://MyApp/hangfire时,它都会重定向到我在web.config中配置的应用程序登录页面: <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="960" /> </authentication> 当我发布到我的主机时,它不会在我的本地计算机上执行此操作. HangFire在我登录时无法识别我的主应用程序提供的身份验证cookie吗?我一般认为,hangfire应用程序不需要身份验证,那么其他配置可能会认为它有什么作用? 更新1: 我按照hangfire docs添加了授权过滤器,但同样的事情发生了.这是我在Startup.cs中的代码: using Hangfire; using Hangfire.Logging; using Hangfire.Dashboard; using Hangfire.SqlServer; using Microsoft.Owin; using OTIS.Web.AppCode; using OTISScheduler.AppServ; using Owin; using System.Web.Security; [assembly: OwinStartup(typeof(OTIS.Web.App_Start.Startup))] namespace OTIS.Web.App_Start { public class Startup { public void Configuration(IAppBuilder app) { app.UseHangfire(config => { config.UseSqlServerStorage("DefaultConnection"); config.UseServer(); //Dashboard authorization config.UseAuthorizationFilters(new AuthorizationFilter { Users = "USERA",// allow only specified users (comma delimited list) Roles = "Account Administrator,Administrator" // allow only specified roles(comma delimited list) }); }); LogProvider.SetCurrentLogProvider(new StubLogProviderForHangfire()); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); var scheduleTasksInitializer = new ScheduleTasksInitializer(); scheduleTasksInitializer.ScheduleTasks(); } } } 更新2: 根据更多detailed instructions showing basic authentication,我也尝试了这个…仍然没有运气..将我转到我的应用程序的登录页面. config.UseAuthorizationFilters( new BasicAuthAuthorizationFilter( new BasicAuthAuthorizationFilterOptions { // Require secure connection for dashboard RequireSsl = false,SslRedirect = false,// Case sensitive login checking LoginCaseSensitive = true,// Users Users = new[] { new BasicAuthAuthorizationUser { Login = "MyLogin",// Password as plain text PasswordClear = "MyPwd" } } })); 解决方法
对于较新的版本,您应该使用IDashboardAuthorizationFilter.使用using语句,它将如下所示:
using System.Web; using Hangfire.Annotations; using Hangfire.Dashboard; namespace Scheduler.Hangfire { public class HangFireAuthorizationFilter : IDashboardAuthorizationFilter { public bool Authorize([NotNull] DashboardContext context) { //can add some more logic here... return HttpContext.Current.User.Identity.IsAuthenticated; } } } 然后在配置部分: app.UseHangfireDashboard("/jobs",new DashboardOptions() { Authorization = new [] {new HangFireAuthorizationFilter()} }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 如何使用jQuery ajax避免快速结果的“闪烁”进度
- entity-framework-4 – 当超出范围时,Ninject不调用对对象的
- openxml – 在Asp.net核心1.0中使用Microsoft.Office.Inter
- .net – 如何将变量传递给SqlDataSource的SelectCommand?
- asp.net – 访问母版页中的祖父母内容占位符
- asp.net-mvc – ASP.NET MVC – 当参数为null时绑定空集合
- ASP.NET ReportViewer在本地模式下非常慢
- asp.net – 如何提取与Outlook正在显示的employeeID属性值相
- asp.net-mvc – ASP.NET MVC:如何从Html.ActionLink链接中
- asp.net-mvc-4 – Windows身份验证和Asp.Net Web API
- asp.net-mvc-4 – ASP.NET MVC 4.0 RC和Newsoft.
- ASP.Net会话超时检测:Session.IsNewSession和Se
- asp.net-mvc – 未在ELMAH中记录的错误
- 文件上传 – 以经典的asp上传文件
- asp.net-mvc – 如何将HTML5表单操作链接到ASP.N
- asp.net-mvc – 如何建立“后退”链接?
- asp.net – System.Runtime.InteropServices.COM
- asp.net – 如何强制ListView以编程方式显示第一
- asp.net-mvc – 获取文件内容的绝对路径
- 如何在ASP.NET MVC中使用flot和jQuery?