pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="yokm0mi" 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="g20isgc" 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="smswsqu" 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>

                            主站蜘蛛池模板: 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 | 上海律师事务所_上海刑事律师免费咨询平台-煊宏律师事务所 | 海日牌清洗剂-打造带电清洗剂、工业清洗剂等清洗剂国内一线品牌 海外整合营销-独立站营销-社交媒体运营_广州甲壳虫跨境网络服务 | 重庆网站建设,重庆网站设计,重庆网站制作,重庆seo,重庆做网站,重庆seo,重庆公众号运营,重庆小程序开发 | 重庆钣金加工厂家首页-专业定做监控电视墙_操作台 | 一体化污水处理设备-一体化净水设备-「山东梦之洁水处理」 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 四川职高信息网-初高中、大专、职业技术学校招生信息网 | TwistDx恒温扩增-RAA等温-Jackson抗体-默瑞(上海)生物科技有限公司 | 冷水机,风冷冷水机,水冷冷水机,螺杆冷水机专业制造商-上海祝松机械有限公司 | 上海皓越真空设备有限公司官网-真空炉-真空热压烧结炉-sps放电等离子烧结炉 | 金属软管_不锈钢金属软管_巩义市润达管道设备制造有限公司 | 河南正规膏药生产厂家-膏药贴牌-膏药代加工-修康药业集团官网 | 青州开防盗门锁-配汽车芯片钥匙-保险箱钥匙-吉祥修锁店 | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | 全国国际学校排名_国际学校招生入学及学费-学校大全网 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 打造全球沸石生态圈 - 国投盛世 锂电混合机-新能源混合机-正极材料混料机-高镍,三元材料混料机-负极,包覆混合机-贝尔专业混合混料搅拌机械系统设备厂家 | 德州网站开发定制-小程序开发制作-APP软件开发-「两山开发」 | 驾驶人在线_专业学车门户网站 | 路斯特伺服驱动器维修,伦茨伺服驱动器维修|万骏自动化百科 | 新疆散热器,新疆暖气片,新疆电锅炉,光耀暖通公司 | 冷油器-冷油器换管改造-连云港灵动列管式冷油器生产厂家 | 昆山新莱洁净应用材料股份有限公司-卫生级蝶阀,无菌取样阀,不锈钢隔膜阀,换向阀,离心泵 | 谷歌关键词优化-外贸网站优化-Google SEO小语种推广-思亿欧外贸快车 | 热缩管切管机-超声波切带机-织带切带机-无纺布切布机-深圳市宸兴业科技有限公司 | 纸张环压仪-纸张平滑度仪-杭州纸邦自动化技术有限公司 | 头条搜索极速版下载安装免费新版,头条搜索极速版邀请码怎么填写? - 欧远全 | 智能化的检漏仪_气密性测试仪_流量测试仪_流阻阻力测试仪_呼吸管快速检漏仪_连接器防水测试仪_车载镜头测试仪_奥图自动化科技 | 欧盟ce检测认证_reach检测报告_第三方检测中心-深圳市威腾检验技术有限公司 | 水平筛厂家-三轴椭圆水平振动筛-泥沙震动筛设备_山东奥凯诺矿机 包装设计公司,产品包装设计|包装制作,包装盒定制厂家-汇包装【官方网站】 | 不锈钢散热器,冷却翅片管散热器厂家-无锡市烨晟化工装备科技有限公司 | 山东彩钢板房,山东彩钢活动房,临沂彩钢房-临沂市贵通钢结构工程有限公司 | 【北京写字楼出租_写字楼租赁_办公室出租网/出售】-远行地产官网 | 酒万铺-酒水招商-酒水代理| 武汉高低温试验机-现货恒温恒湿试验箱-高低温湿热交变箱价格-湖北高天试验设备 | 防渗土工膜|污水处理防渗膜|垃圾填埋场防渗膜-泰安佳路通工程材料有限公司 | 管形母线,全绝缘铜管母线厂家-山东佰特电气科技有限公司 | 集装箱箱号识别_自重载重图像识别_铁路车号自动识别_OCR图像识别 | 数控走心机-双主轴走心机厂家-南京建克 | ERP企业管理系统永久免费版_在线ERP系统_OA办公_云版软件官网 |