久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='vqSVM'></tfoot>

  • <legend id='vqSVM'><style id='vqSVM'><dir id='vqSVM'><q id='vqSVM'></q></dir></style></legend>

    1. <i id='vqSVM'><tr id='vqSVM'><dt id='vqSVM'><q id='vqSVM'><span id='vqSVM'><b id='vqSVM'><form id='vqSVM'><ins id='vqSVM'></ins><ul id='vqSVM'></ul><sub id='vqSVM'></sub></form><legend id='vqSVM'></legend><bdo id='vqSVM'><pre id='vqSVM'><center id='vqSVM'></center></pre></bdo></b><th id='vqSVM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vqSVM'><tfoot id='vqSVM'></tfoot><dl id='vqSVM'><fieldset id='vqSVM'></fieldset></dl></div>

        <small id='vqSVM'></small><noframes id='vqSVM'>

          <bdo id='vqSVM'></bdo><ul id='vqSVM'></ul>

      1. Asp Core 2.1 Jwt + 身份.userManager 存儲沒有實現 IUse

        Asp Core 2.1 Jwt + Identity. userManager store does not implement IUserRoleStore(Asp Core 2.1 Jwt + 身份.userManager 存儲沒有實現 IUserRoleStore)
        <i id='aVmSZ'><tr id='aVmSZ'><dt id='aVmSZ'><q id='aVmSZ'><span id='aVmSZ'><b id='aVmSZ'><form id='aVmSZ'><ins id='aVmSZ'></ins><ul id='aVmSZ'></ul><sub id='aVmSZ'></sub></form><legend id='aVmSZ'></legend><bdo id='aVmSZ'><pre id='aVmSZ'><center id='aVmSZ'></center></pre></bdo></b><th id='aVmSZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aVmSZ'><tfoot id='aVmSZ'></tfoot><dl id='aVmSZ'><fieldset id='aVmSZ'></fieldset></dl></div>

        <small id='aVmSZ'></small><noframes id='aVmSZ'>

          <tbody id='aVmSZ'></tbody>
                <bdo id='aVmSZ'></bdo><ul id='aVmSZ'></ul>

                <tfoot id='aVmSZ'></tfoot>
                • <legend id='aVmSZ'><style id='aVmSZ'><dir id='aVmSZ'><q id='aVmSZ'></q></dir></style></legend>
                  本文介紹了Asp Core 2.1 Jwt + 身份.userManager 存儲沒有實現 IUserRoleStore的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試在 ASP Net Core 2.1 中使用 Jwt auth 和 Identity

                  I am trying to work with Jwt auth and Identity in ASP Net Core 2.1

                  在我的 Startup.cs 我有:

                  In my Startup.cs I have:

                  services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                      .AddJwtBearer(options =>
                      {
                          options.RequireHttpsMetadata = false;
                          options.TokenValidationParameters = new TokenValidationParameters
                          {
                              ValidateIssuer = true,
                              ValidIssuer = AuthOptions.ISSUER,
                              ValidateAudience = true,
                              ValidAudience = AuthOptions.AUDIENCE,
                              ValidateLifetime = true,
                              IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(),
                              ValidateIssuerSigningKey = true,
                          };
                      });
                  
                  var builder = services.AddIdentityCore<User>(options =>
                  {
                      // Password settings
                      ...
                      // Lockout settings
                      ...
                      // User settings
                      options.User.RequireUniqueEmail = true;
                  }).AddEntityFrameworkStores<ApplicationDbContext>();
                  

                  builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole), builder.Services);

                  builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole), builder.Services);

                  然后在 SecurityService.cs 中我嘗試使用此語句獲取角色

                  Then in SecurityService.cs I am trying to get roles by using this statement

                  var roles = await _userManager.GetRolesAsync(user);
                  

                  并拋出以下異常:

                  NotSupportedException:存儲未實現 IUserRoleStore
                  Microsoft.AspNetCore.Identity.UserManager.GetUserRoleStore()

                  NotSupportedException: Store does not implement IUserRoleStore
                  Microsoft.AspNetCore.Identity.UserManager.GetUserRoleStore()

                  我發現它是因為 AddIdentityCore:如果我使用AddIdentity<User, IdentityRole> 代替它工作,但隨后 [Authorize] 不起作用

                  I found it because of AddIdentityCore: If I use AddIdentity<User, IdentityRole> instead it works, but then [Authorize] doesn't work

                  有沒有人遇到過類似的情況,或者為什么會發生這種情況?

                  Does anybody faced similar situation, or why it can happen?

                  推薦答案

                  當您使用 AddIdentity 時,該調用會配置默認身份驗證方案,如下所示 (來源):

                  When you use AddIdentity<TUser, TRole>, that call configures the default authentication scheme, like so (source):

                  services.AddAuthentication(options =>
                  {
                      options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme;
                      options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme;
                      options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
                  })
                  

                  在您的 Startup.ConfigureServices 中,您有以下內容,設置了默認身份驗證方案:

                  In your Startup.ConfigureServices, you have the following, which also sets the default authentication scheme:

                  services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                  

                  由于這是定義的順序(AddIdentityafter AddAuthentication),默認是從Jwt變成Identity,這樣當您使用 [Authorize],身份驗證過程現在期望使用 Identity 而不是 Jwt.

                  Because of the order this is defined (AddIdentity is after AddAuthentication), the default is changing from Jwt to Identity, so that when you use [Authorize], the authentication process is now expecting to use Identity rather than Jwt.

                  要解決這個問題,最簡單的選擇是切換 AddIdentityAddAuthentication 的順序,這樣 JwtBearer 調用就排在最后,因此獲勝".您還需要更明確地設置 DefaultAuthenticateSchemeDefaultChallengeScheme:

                  To resolve this, the simplest option is to switch the order of AddIdentity and AddAuthentication, so the JwtBearer call comes last and therefore "wins". You'll also need to be more explicit and set both DefaultAuthenticateScheme and DefaultChallengeScheme:

                  services.AddAuthentication(options =>
                  {
                      options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                      options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
                  })
                  .AddJwtBearer(...);
                  

                  另一個選項是在 [Authorize] 屬性中顯式,調用 which 您要使用的身份驗證方案,如以下兩行之一:

                  Another option is to be explicit in the [Authorize] attribute, calling out which authentication scheme you want to use, like either of the following two lines:

                  [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
                  [Authorize(AuthenticationSchemes = IdentityConstants.ApplicationScheme)]
                  

                  似乎第一個選項最適合您的用例,但如果您在進一步使用 Identity 時需要它(還有更多 - 例如使用策略),那么很高興知道第二個選項存在.

                  It seems the first option would be most appropriate for your use-case, but it's good to know that this second option exists should you need it as you go further with Identity (there are more - e.g. using policies).

                  這篇關于Asp Core 2.1 Jwt + 身份.userManager 存儲沒有實現 IUserRoleStore的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)

                  <small id='zvfeM'></small><noframes id='zvfeM'>

                  <tfoot id='zvfeM'></tfoot>
                  <i id='zvfeM'><tr id='zvfeM'><dt id='zvfeM'><q id='zvfeM'><span id='zvfeM'><b id='zvfeM'><form id='zvfeM'><ins id='zvfeM'></ins><ul id='zvfeM'></ul><sub id='zvfeM'></sub></form><legend id='zvfeM'></legend><bdo id='zvfeM'><pre id='zvfeM'><center id='zvfeM'></center></pre></bdo></b><th id='zvfeM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zvfeM'><tfoot id='zvfeM'></tfoot><dl id='zvfeM'><fieldset id='zvfeM'></fieldset></dl></div>

                  <legend id='zvfeM'><style id='zvfeM'><dir id='zvfeM'><q id='zvfeM'></q></dir></style></legend>

                      <tbody id='zvfeM'></tbody>

                      • <bdo id='zvfeM'></bdo><ul id='zvfeM'></ul>

                            主站蜘蛛池模板: 九九热在线观看视频 | 精品福利av导航 | 在线观看亚洲专区 | 国产精品3区 | 日韩免费一级 | 国产99久久精品一区二区永久免费 | 亚洲高清在线观看 | 91 在线| 久久久爽爽爽美女图片 | 91成人免费| 中文av字幕| 日韩三级一区 | 国产一级一级 | 成人毛片在线观看 | 国产精品美女久久久久aⅴ国产馆 | 拍戏被cao翻了h承欢 | 美女131mm久久爽爽免费 | 国产精品毛片 | 久久99精品国产99久久6男男 | av国产在线观看 | 一级做a爰片性色毛片16美国 | 99久久精品国产一区二区三区 | 国产午夜精品久久久 | 龙珠z国语版在线观看 | 中文字幕高清一区 | 国产精品海角社区在线观看 | 日韩免费网 | 国产精品视频免费观看 | 99视频免费在线 | 亚洲综合日韩精品欧美综合区 | 亚洲成人精 | 国产a视频 | 亚洲乱码一区二区三区在线观看 | www.亚洲精品 | 国产福利在线 | 国产免费高清 | 日韩一级免费观看 | 久久毛片 | 不卡在线一区 | 国产一区 | www久久av|