本文整理匯總了C#中System.IdentityModel.Services.ClaimsPrincipalPermission類的典型用法代碼示例。如果您正苦於以下問題:C# ClaimsPrincipalPermission類的具體用法?C# ClaimsPrincipalPermission怎麽用?C# ClaimsPrincipalPermission使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClaimsPrincipalPermission類屬於System.IdentityModel.Services命名空間,在下文中一共展示了ClaimsPrincipalPermission類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;
using System.Security.Claims;
using System.IdentityModel.Services;
namespace ClaimsBasedAuthorization
{
/// <summary>
/// Program illustrates using Claims-based authorization
/// </summary>
class Program
{
static void Main(string[] args)
{
//
// Method 1. Simple access check using static method.
// Expect this to be most common method.
//
ClaimsPrincipalPermission.CheckAccess("resource", "action");
//
// Method 2. Programmatic check using the permission class
// Follows model found at http://msdn.microsoft.com/library/system.security.permissions.principalpermission.aspx
//
ClaimsPrincipalPermission cpp = new ClaimsPrincipalPermission("resource", "action");
cpp.Demand();
//
// Method 3. Access check interacting directly with the authorization manager.
//
ClaimsAuthorizationManager am = new ClaimsAuthorizationManager();
am.CheckAccess(new AuthorizationContext((ClaimsPrincipal)Thread.CurrentPrincipal, "resource", "action"));
//
// Method 4. Call a method that is protected using the permission attribute class
//
ProtectedMethod();
Console.WriteLine("Press [Enter] to continue.");
Console.ReadLine();
}
//
// Declarative access check using the permission class. The caller must satisfy both demands.
//
[ClaimsPrincipalPermission(SecurityAction.Demand, Resource = "resource", Operation = "action")]
[ClaimsPrincipalPermission(SecurityAction.Demand, Resource = "resource1", Operation = "action1")]
static void ProtectedMethod()
{
}
}
}