當前位置: 首頁>>代碼示例>>C#>>正文


C# AuthorizationContext類代碼示例

本文整理匯總了C#中AuthorizationContext的典型用法代碼示例。如果您正苦於以下問題:C# AuthorizationContext類的具體用法?C# AuthorizationContext怎麽用?C# AuthorizationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AuthorizationContext類屬於命名空間,在下文中一共展示了AuthorizationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: HandleNonHttpsRequest

 protected override void HandleNonHttpsRequest(AuthorizationContext filterContext)
 {
     if (!filterContext.HttpContext.Request.IsLocal)
     {
         base.HandleNonHttpsRequest(filterContext);
     }
 }
開發者ID:winmissupport,項目名稱:FeatureUpate,代碼行數:7,代碼來源:RequireHttpsWhenLiveAttribute.cs

示例2: HandleAsync

 public async Task HandleAsync(AuthorizationContext context)
 {
     if (await Handler(context))
     {
         context.Succeed(this);
     }
 }
開發者ID:,項目名稱:,代碼行數:7,代碼來源:

示例3: OnAuthorization

 protected override void OnAuthorization(AuthorizationContext filterContext)
 {
     if(!AuthHelper.IsAllowEnterAdminPlatform)
     {
         throw new HttpException(401, "您沒有權限進行此操作!");
     }
 }
開發者ID:diycp,項目名稱:Magicodes.NET,代碼行數:7,代碼來源:AdminControllerBase.cs

示例4: HandleUnauthorizedRequest

        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            //you can change to any controller or html page.
            //filterContext.Result = new RedirectResult("/Home/NaoAutorizado");
            filterContext.Result = new RedirectResult("/Identificacao/Autenticacao/NaoAutorizado");

        }
開發者ID:tendenciaconsult,項目名稱:RedivivusProd,代碼行數:7,代碼來源:MenuAuthorizeAttribute.cs

示例5: HandleUnauthorizedRequest

 protected override void HandleUnauthorizedRequest(AuthorizationContext context)
 {
     if (context.RequestContext.HttpContext.Request.Headers["X-Requested-With"] != "XMLHttpRequest")
     {
         context.Result = new RedirectResult("/account/sign-in");
     }
 }
開發者ID:manishkungwani,項目名稱:frapid,代碼行數:7,代碼來源:RestrictAnonymousAttribute.cs

示例6: CheckAccess

        public override bool CheckAccess(AuthorizationContext context)
        {
            var identity = context.Principal.Identity as IClaimsIdentity;
            if (identity == null || !identity.IsAuthenticated)
            {
                return false;
            }

            var nameIdentifier = identity.Claims.FirstOrDefault(c => c.ClaimType == ClaimTypes.NameIdentifier);
            if (nameIdentifier == null)
            {
                return false;
            }

            var resourceUri = new Uri(context.Resource.First().Value, UriKind.RelativeOrAbsolute);
            foreach (var validator in this.storageRequestValidators)
            {
                if (validator.DoesRequestApply(resourceUri))
                {
                    return validator.ValidateRequest(nameIdentifier.Value, HttpContext.Current.Request);
                }
            }

            return base.CheckAccess(context);
        }
開發者ID:ayant,項目名稱:Discount-aggregator,代碼行數:25,代碼來源:UserPrivilegesAuthorizationManager.cs

示例7: OnAuthorization

        // Override method
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            // Get a reference to the user
            var user = filterContext.HttpContext.User as ClaimsPrincipal;

            // Matches (below) are case-insensitive

            // Look for claims that match the incoming type
            // The matchingClaims will be a collection of zero or more matching claims
            var matchingClaims = user.Claims
                .Where(c => c.Type.ToLower().Contains(ClaimType.ToLower()));

            // Attempt to locate matching values
            var matchedClaim = false;
            foreach (var claim in matchingClaims)
            {
                if (claim.Value.ToLower() == ClaimValue.ToLower())
                {
                    matchedClaim = true;
                    break;
                }
            }

            if (matchedClaim)
            {
                // Yes, authorized
                base.OnAuthorization(filterContext);
            }
            else
            {
                // No, not authorized
                base.HandleUnauthorizedRequest(filterContext);
            }
        }
開發者ID:peteratseneca,項目名稱:bti420winter2016,代碼行數:35,代碼來源:CustomAuthorizeAttributes.cs

示例8: OnAuthorization

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var user = HttpContext.Current.User as ClaimsPrincipal;
            var controllerGroup = filterContext.Controller.GetType().GetCustomAttribute<ClaimsGroupAttribute>();

            if (controllerGroup == null)
            {
                return;
            }

            var actionClaim = (ClaimsActionAttribute)filterContext.ActionDescriptor.GetCustomAttributes(typeof(ClaimsActionAttribute), true).FirstOrDefault();

            actionClaim = actionClaim ?? new ClaimsActionAttribute(ClaimsActions.Index);

            var groupId = controllerGroup.GetGroupId();
            var claimValue = actionClaim .Claim.ToString();

            var hasClaim = user.HasClaim(groupId, claimValue);
            if (!hasClaim)
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary()
                {
                    { "controller", "errors" },
                    { "action", "Unauthorised" },
                    { "area", "" }
                });
            }
        }
開發者ID:ruskey86,項目名稱:ClaimsAuthorisation,代碼行數:28,代碼來源:ClaimsAuthorisationFilter.cs

示例9: HandleAsync

 public async Task HandleAsync(AuthorizationContext context)
 {
     foreach (var handler in context.Requirements.OfType<IAuthorizationHandler>())
     {
         await handler.HandleAsync(context);
     }
 }
開發者ID:leloulight,項目名稱:Security,代碼行數:7,代碼來源:PassThroughAuthorizationHandler.cs

示例10: CreateResult

 protected ActionResult CreateResult(AuthorizationContext filterContext)
 {
     var viewName = "~/Views/Shared/AccessDenied.cshtml";
     return new PartialViewResult
     {
         ViewName = viewName
     };
 }
開發者ID:raselahmmedgit,項目名稱:my-apps,代碼行數:8,代碼來源:UserAuthorize.cs

示例11: OnAuthorization

 public void OnAuthorization(AuthorizationContext context)
 {
     context.Result = new ContentResult()
     {
         Content = "You are unauthorized!!",
         StatusCode = 401
     };
 }
開發者ID:phinq19,項目名稱:git_example,代碼行數:8,代碼來源:AllRequestsBlockingAuthorizationFilter.cs

示例12: OnAuthorization

        public virtual void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            filterContext.Controller.ValidateRequest = EnableValidation;
        }
開發者ID:mhinze,項目名稱:msmvc,代碼行數:9,代碼來源:ValidateInputAttribute.cs

示例13: Authorize

 public bool Authorize(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements)
 {
     var authContext = new AuthorizationContext(requirements, user, resource);
     foreach (var handler in _handlers)
     {
         handler.Handle(authContext);
     }
     return authContext.HasSucceeded;
 }
開發者ID:james-wu,項目名稱:Security,代碼行數:9,代碼來源:DefaultAuthorizationService.cs

示例14: Fail

        protected virtual void Fail(AuthorizationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.Result = new HttpUnauthorizedResult();
        }
開發者ID:huoxudong125,項目名稱:Mvc,代碼行數:9,代碼來源:AuthorizationFilterAttribute.cs

示例15: HasAllowAnonymous

        protected virtual bool HasAllowAnonymous(AuthorizationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return context.Filters.Any(item => item is IAllowAnonymousFilter);
        }
開發者ID:huoxudong125,項目名稱:Mvc,代碼行數:9,代碼來源:AuthorizationFilterAttribute.cs


注:本文中的AuthorizationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。