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


C# AuthorizationContext.SkipAuthorisation方法代碼示例

本文整理匯總了C#中System.Web.Mvc.AuthorizationContext.SkipAuthorisation方法的典型用法代碼示例。如果您正苦於以下問題:C# AuthorizationContext.SkipAuthorisation方法的具體用法?C# AuthorizationContext.SkipAuthorisation怎麽用?C# AuthorizationContext.SkipAuthorisation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Web.Mvc.AuthorizationContext的用法示例。


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

示例1: OnAuthorization

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.SkipAuthorisation())
            {
                return;
            }

            var identity = (ClaimsIdentity)filterContext.HttpContext.User.Identity;
            var hasEmailVerifiedClaim = identity.HasClaim(c => c.Type.Equals(JwtClaimTypes.EmailVerified));

            if (hasEmailVerifiedClaim && identity.Claims.Single(c => c.Type.Equals(JwtClaimTypes.EmailVerified)).Value.Equals("false", StringComparison.InvariantCultureIgnoreCase))
            {
                bool userIsInternal = ((ClaimsIdentity)filterContext.HttpContext.User.Identity).HasClaim(
                    ClaimTypes.AuthenticationMethod, Claims.CanAccessInternalArea);

                if (userIsInternal)
                {
                    filterContext.Result = new RedirectResult("~/Admin/Account/AdminAccountActivationRequired");
                }
                else
                {
                    filterContext.Result = new RedirectResult("~/Account/UserAccountActivationRequired");
                }
            }
        }
開發者ID:EnvironmentAgency,項目名稱:prsd-weee,代碼行數:25,代碼來源:UserAccountActivationAttribute.cs

示例2: OnAuthorization

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.IsChildAction || filterContext.SkipAuthorisation())
            {
                return;
            }

            var principal = (ClaimsPrincipal)filterContext.HttpContext.User;
            var identity = (ClaimsIdentity)filterContext.HttpContext.User.Identity;

            if (!identity.IsAuthenticated)
            {
                return;
            }

            var organisationRegistered = identity.HasClaim(c => c.Type.Equals(ClaimTypes.OrganisationId));

            if (principal.IsInternalUser())
            {
                return;
            }

            if (!organisationRegistered)
            {
                filterContext.Result = new RedirectToRouteResult(
                    new RouteValueDictionary(new { controller = "Registration", action = "CreateNewOrganisation", area = string.Empty }));
            }
        }
開發者ID:EnvironmentAgency,項目名稱:prsd-iws,代碼行數:28,代碼來源:OrganisationRequiredAttribute.cs

示例3: OnAuthorization

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.IsChildAction || filterContext.SkipAuthorisation())
            {
                return;
            }

            var principal = (ClaimsPrincipal)filterContext.HttpContext.User;
            var identity = (ClaimsIdentity)principal.Identity;

            var hasEmailVerifiedClaim = identity.HasClaim(c => c.Type.Equals(JwtClaimTypes.EmailVerified));

            if (hasEmailVerifiedClaim && identity.Claims.Any(c => 
                    c.Type.Equals(JwtClaimTypes.EmailVerified) 
                    && c.Value.Equals("false", StringComparison.InvariantCultureIgnoreCase)))                
            {
                var redirectAddress = principal.IsInternalUser() 
                    ? new RouteValueDictionary(new { controller = "Registration", action = "AdminEmailVerificationRequired", area = "Admin" })
                    : new RouteValueDictionary(new { controller = "Account", action = "EmailVerificationRequired", area = string.Empty });

                filterContext.Result = new RedirectToRouteResult(redirectAddress);
            }
        }
開發者ID:EnvironmentAgency,項目名稱:prsd-iws,代碼行數:23,代碼來源:EmailVerificationRequiredAttribute.cs


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