簡體   English   中英

我可以在新的 ClaimTypes.Role 中使用多個角色名稱嗎

[英]Can i use more than role name in new ClaimTypes.Role

我有這個方法添加 cookies 和 ClaimType 角色

private async void AddCookies(string role)
    {
     var claim = new List<Claim>
     {
       new Claim(ClaimTypes.Role , role.ToString()),
     }
    }

這是我的數據庫表 Users And Roels And Users Roles 每個用戶擁有的不僅僅是角色

我嘗試使用數組,但不像這個例子那樣與我一起工作

 private async void AddCookies(string[] role)
        {
         var claim = new List<Claim>
         {
           new Claim(ClaimTypes.Role , role.ToString()),
         }
        }

您沒有為數組的每個元素添加一個角色,而是將整個數組作為參數傳遞給 Claim() 構造函數。 您必須遍歷角色數組並為每個角色創建新聲明。

    private async void AddCookies(string[] roles)
    {
        var claims = new List<Claim>();

        foreach(var role in roles)
        {      
            var claim = new Claim(ClaimTypes.Role, role);

            claims.Add(claim);
        }       
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM