当前位置: 首页>>代码示例>>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;未经允许,请勿转载。