Asp.net 코어 구성 및 패널 hangfire의 사용

1, 클래스 인증 검사의 정의 DyDashboardAuthorizationFilter

    ///  <요약> 
    /// Hangfire仪表盘配置授权
     ///  </ 요약> 
    공용  클래스 MyDashboardAuthorizationFilter : IDashboardAuthorizationFilter 
    { 
        공개  부울 권한 부여 ([NOTNULL] DashboardContext 컨텍스트) 
        { 
            VAR 으로 HttpContext = context.GetHttpContext (); 

            VAR의 헤더 httpContext.Request.Headers = [ " 권한 " ]; 

            경우 ( 문자열 .IsNullOrWhiteSpace (헤더)) 
            { 
                SetChallengeResponse (HttpContext를); 
                돌아  거짓 ; 
            }

            VAR authValues = System.Net.Http.Headers.AuthenticationHeaderValue.Parse (헤더); 

            만약 (! " 기본 " .Equals (authValues.Scheme, StringComparison.InvariantCultureIgnoreCase)) 
            { 
                SetChallengeResponse (HttpContext를); 
                돌아  거짓 ; 
            } 

            VAR의 파라미터 = System.Text.Encoding.UTF8.GetString (Convert.FromBase64String (authValues.Parameter));
            VAR의 부품 = parameter.Split ( " : " ); 

            경우 (parts.Length < 2 )  
            {
                SetChallengeResponse (HttpContext에);
                돌아  거짓 ; 
            } 

            var에 자명 부품 = [ 0 ];
            VAR의 암호 부 = [ 1 ]; 

            경우 ( 문자열 .IsNullOrWhiteSpace (사용자 이름) || 문자열 .IsNullOrWhiteSpace (비밀번호)) 
            { 
                SetChallengeResponse (HttpContext를); 
                돌아  거짓 ; 
            } 

            경우 (사용자 이름 == " 사용자 " && 암호 == " " ) 
            { 
                반환  사실 ; 
            }

            SetChallengeResponse (HttpContext에); 
            돌아  거짓 ; 
        } 

        개인  공극 SetChallengeResponse (HttpContext에있는 HttpContext) 
        { 
            httpContext.Response.StatusCode = 401 ; 
            httpContext.Response.Headers.Append ( " WWW 인증 " , " 기본 영역 = \"Hangfire 대시 보드 \ " " ); 
            httpContext.Response.WriteAsync ( " 인증이 필요합니다. " ); 
        } 
    }

 

도 2에있어서의 구성의 startup.cs

           // hangfire 예약 태스크 활성화 
            app.UseHangfireServer을 (); 

            // 접근로 제어 권한 대시 구성 
            app.UseHangfireDashboard ( " / hangfire " , 새로운 새 Hangfire.DashboardOptions 
            { 
                권한 부여 = 새로운 새 [{ 새로운 새 MyDashboardAuthorizationFilter ()} 
            }) ;

 HTTP : // 로컬 호스트 : 포트 / hangfire 3, 브라우저를 엽니 다. 그리고 사용자 이름과 암호를 입력

당신은 볼 수 있습니다 :

 

추천

출처www.cnblogs.com/dayang12525/p/11320448.html