本文整理汇总了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);
}
}
示例2: HandleAsync
public async Task HandleAsync(AuthorizationContext context)
{
if (await Handler(context))
{
context.Succeed(this);
}
}
示例3: OnAuthorization
protected override void OnAuthorization(AuthorizationContext filterContext)
{
if(!AuthHelper.IsAllowEnterAdminPlatform)
{
throw new HttpException(401, "您没有权限进行此操作!");
}
}
示例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");
}
示例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");
}
}
示例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);
}
示例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);
}
}
示例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", "" }
});
}
}
示例9: HandleAsync
public async Task HandleAsync(AuthorizationContext context)
{
foreach (var handler in context.Requirements.OfType<IAuthorizationHandler>())
{
await handler.HandleAsync(context);
}
}
示例10: CreateResult
protected ActionResult CreateResult(AuthorizationContext filterContext)
{
var viewName = "~/Views/Shared/AccessDenied.cshtml";
return new PartialViewResult
{
ViewName = viewName
};
}
示例11: OnAuthorization
public void OnAuthorization(AuthorizationContext context)
{
context.Result = new ContentResult()
{
Content = "You are unauthorized!!",
StatusCode = 401
};
}
示例12: OnAuthorization
public virtual void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
filterContext.Controller.ValidateRequest = EnableValidation;
}
示例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;
}
示例14: Fail
protected virtual void Fail(AuthorizationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.Result = new HttpUnauthorizedResult();
}
示例15: HasAllowAnonymous
protected virtual bool HasAllowAnonymous(AuthorizationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return context.Filters.Any(item => item is IAllowAnonymousFilter);
}