本文整理汇总了C#中ISecurityContext.CurrenUserAuthenticated方法的典型用法代码示例。如果您正苦于以下问题:C# ISecurityContext.CurrenUserAuthenticated方法的具体用法?C# ISecurityContext.CurrenUserAuthenticated怎么用?C# ISecurityContext.CurrenUserAuthenticated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISecurityContext
的用法示例。
在下文中一共展示了ISecurityContext.CurrenUserAuthenticated方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Enforce
public PolicyResult Enforce(ISecurityContext context)
{
if (context.CurrenUserAuthenticated())
{
return PolicyResult.CreateFailureResult(this, "Authenticated access denied");
}
return PolicyResult.CreateSuccessResult(this);
}
示例2: Enforce
public PolicyResult Enforce(ISecurityContext context)
{
if (context.CurrenUserAuthenticated() == false)
return PolicyResult.CreateFailureResult(this, "Anonymous access denied");
if (context.CurrenUserRoles() == null || context.CurrenUserRoles().Any() == false)
return PolicyResult.CreateFailureResult(this, "Access denied");
if (_requiredRoles.Any(requiredRole => context.CurrenUserRoles().Contains(requiredRole) == false))
{
const string message = "Access requires all of the following roles: {0}.";
var formattedMessage = string.Format(message, GetRoles());
return PolicyResult.CreateFailureResult(this, formattedMessage);
}
return PolicyResult.CreateSuccessResult(this);
}
示例3: Enforce
public PolicyResult Enforce(ISecurityContext context)
{
if (context.CurrenUserAuthenticated() == false)
return PolicyResult.CreateFailureResult(this, "Anonymous access denied");
if (context.CurrenUserRoles() == null || context.CurrenUserRoles().Any() == false)
return PolicyResult.CreateFailureResult(this, "Access denied");
foreach (var requiredRole in _requiredRoles)
{
foreach (var role in context.CurrenUserRoles())
{
if (requiredRole.ToString() == role.ToString())
{
return PolicyResult.CreateSuccessResult(this);
}
}
}
const string message = "Access requires one of the following roles: {0}.";
var formattedMessage = string.Format(message, GetRoles());
return PolicyResult.CreateFailureResult(this, formattedMessage);
}
示例4: Enforce
public PolicyResult Enforce(ISecurityContext context)
{
var authenticated = context.CurrenUserAuthenticated();
var roles = context.CurrenUserRoles();
return PolicyResult.CreateSuccessResult(this);
}