本文整理汇总了C#中IAuthorizationService.AuthorizeAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthorizationService.AuthorizeAsync方法的具体用法?C# IAuthorizationService.AuthorizeAsync怎么用?C# IAuthorizationService.AuthorizeAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAuthorizationService
的用法示例。
在下文中一共展示了IAuthorizationService.AuthorizeAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public async Task Invoke(HttpContext context, IAuthorizationService authorizationService) {
if(context.Request.Path.StartsWithSegments(_path)) {
if(await authorizationService.AuthorizeAsync(context.User, null, _policy)) {
await _next(context);
}
}
}
示例2: Invoke
public async Task Invoke(HttpContext httpContext,
IAuthorizationService authorizationService)
{
if(httpContext.Request.Path.StartsWithSegments(_path))
{
var authorized = await authorizationService.AuthorizeAsync(
httpContext.User, null, _policyName);
if (!authorized)
{
await httpContext.Authentication.ChallengeAsync();
return;
}
}
await _next(httpContext);
}
示例3: Invoke
public async Task Invoke(HttpContext httpContext, IAuthorizationService authorizationService)
{
var middlewarePlugins = new List<IMiddlewarePlugin>();
foreach (var record in _settings.Value.GlobalPath.OptIn)
{
foreach (var path in record.Paths)
{
if (httpContext.Request.Path.StartsWithSegments(path))
{
// gotcha.
var authorized = await authorizationService.AuthorizeAsync(
httpContext.User, null, _policyName);
if (!authorized)
{
await httpContext.Authentication.ChallengeAsync();
return;
}
}
}
}
await _next(httpContext);
}