public void OnAuthorization(AuthorizationFilterContext context)
        {
            if (!context.HttpContext.User.Identity.IsAuthenticated)
            {
                context.Result = new RedirectToRouteResult(new RouteValueDictionary(new { area = "Identity", page = "/Account/Login", ReturnUrl = context.HttpContext.Request.Path.ToString() }));
            }


            if (!CustomAuthorizationHelper.ValidarClaimsUsuario(context.HttpContext, _claim.Type, _claim.Value))
            {
                //Voltando acesso negado
                context.Result = new StatusCodeResult(403);
            }
        }
Пример #2
0
 public static IHtmlContent IfClaimShow(this IHtmlContent page, HttpContext context, string claimName, string claimValue)
 {
     return(CustomAuthorizationHelper.ValidarClaimsUsuario(context, claimName, claimValue) ? page: null);
 }
Пример #3
0
 /// <summary>
 /// Extension method para habilitar/desabilitar um elemento (exemplo: botao) dentro da minha razor page se o usuario possuir ou nao uma claim
 /// </summary>
 /// <param name="page"></param>
 /// <param name="claimName"></param>
 /// <param name="claimValue"></param>
 /// <returns></returns>
 public static string IfClaimShow(this RazorPage page, string claimName, string claimValue)
 {
     return(CustomAuthorizationHelper.ValidarClaimsUsuario(page.Context, claimName, claimValue) ? "" : "disabled");
 }
Пример #4
0
 /// <summary>
 /// Extension method para validar dentro da minha razor page se o usuario possui ou nao uma claim
 /// </summary>
 /// <param name="page"></param>
 /// <param name="claimName"></param>
 /// <param name="claimValue"></param>
 /// <returns></returns>
 public static bool IfClaim(this RazorPage page, string claimName, string claimValue)
 {
     return(CustomAuthorizationHelper.ValidarClaimsUsuario(page.Context, claimName, claimValue));
 }