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


C# ClaimsPrincipalPermission類代碼示例

本文整理匯總了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()
        {
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.IdentityModel.Services,代碼行數:55,代碼來源:ClaimsPrincipalPermission


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