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

      <tfoot id='wDujo'></tfoot>

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

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

      1. ASP .NET CORE 2.2 JWT &amp;聲明網站身份認證

        ASP .NET CORE 2.2 JWT amp; Claims identity Authentication for Website(ASP .NET CORE 2.2 JWT amp;聲明網站身份認證)
          <tfoot id='Go1AD'></tfoot>
            <i id='Go1AD'><tr id='Go1AD'><dt id='Go1AD'><q id='Go1AD'><span id='Go1AD'><b id='Go1AD'><form id='Go1AD'><ins id='Go1AD'></ins><ul id='Go1AD'></ul><sub id='Go1AD'></sub></form><legend id='Go1AD'></legend><bdo id='Go1AD'><pre id='Go1AD'><center id='Go1AD'></center></pre></bdo></b><th id='Go1AD'></th></span></q></dt></tr></i><div class="d3m83ww" id='Go1AD'><tfoot id='Go1AD'></tfoot><dl id='Go1AD'><fieldset id='Go1AD'></fieldset></dl></div>

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

                <tbody id='Go1AD'></tbody>
              <legend id='Go1AD'><style id='Go1AD'><dir id='Go1AD'><q id='Go1AD'></q></dir></style></legend>

                • <bdo id='Go1AD'></bdo><ul id='Go1AD'></ul>
                  本文介紹了ASP .NET CORE 2.2 JWT &amp;聲明網站身份認證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有一個 .net core 2.2 api,它生成(在成功登錄時)一個 JWT 令牌,其中包含一個聲明身份,該身份傳遞信息,例如經過身份驗證的用戶的用戶名、權限和角色.

                  I have an .net core 2.2 api which generates (on a successful login) a JWT token which contains a claims identity that passes along information such as the username, permissions and roles of the authenticated user.

                  在我的 .net 核心 2.2 中.Web 應用程序我有一個登錄機制,它通過控制器的用戶檢索 JWT 令牌.

                  In my .net core 2.2. web app I have a login mechanism which retrieves the JWT token via the user of a controller.

                  我的問題是.

                  如何從我的登錄控制器中擴展令牌并設置我的網絡應用程序以包括使用身份驗證機制,如 User.Identity.IsAuthenticatedUser.IsInRole("Admin") 和控制器操作,例如 [Authorize][Authorize(Roles="Admin")]

                  How can I expand the token from within my login controller and set up my web app to include the use of the authentication mechanisms like User.Identity.IsAuthenticated, User.IsInRole("Admin") and controller actions like [Authorize] and [Authorize(Roles="Admin")]

                  我一直致力于查看 facebook/google 等外部身份驗證提供程序背后的源代碼,但無濟于事.

                  I've been directed towards looking at the source code behind external authentication providers such as facebook/google but to no avail.

                  提前致謝.

                  推薦答案

                  第一步是在Startup.cs中使用cookie認證:

                  services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                  .AddCookie();
                  
                  services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
                  

                  Configure 方法中,使用 UseAuthentication 方法調用設置 HttpContext.User 屬性的身份驗證中間件.在調用 UseMvcWithDefaultRouteUseMvc 之前調用 UseAuthentication 方法:

                  In the Configure method, use the UseAuthentication method to invoke the Authentication Middleware that sets the HttpContext.User property. Call the UseAuthentication method before calling UseMvcWithDefaultRoute or UseMvc:

                  app.UseAuthentication();
                  

                  然后在您的身份驗證控制器中,獲取令牌并解碼以獲取聲明后,您應該創建新的 ClaimsIdentity ,添加您的聲明并登錄用戶:

                  Then in your auth controller , after getting token and decode to get the claims , you should create new ClaimsIdentity , add your claims and sign-in user :

                  if (!User.Identity.IsAuthenticated)
                  {
                      var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role);
                      identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, YourName));
                      identity.AddClaim(new Claim(ClaimTypes.Name, YourName));
                      identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
                  
                      //Add your custom claims
                  
                      var principal = new ClaimsPrincipal(identity);
                      await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = true });
                  
                  }
                  

                  之后,您可以使用User.Identity.IsAuthenticatedUser.IsInRole("Admin")[Authorize(Roles="Admin")]:

                  After that , you can useUser.Identity.IsAuthenticated, User.IsInRole("Admin") and [Authorize(Roles="Admin")]:

                  [Authorize(Roles = "Admin")]
                  public IActionResult About()
                  {
                      var result = User.IsInRole("Admin");
                      return View();
                  }
                  

                  這篇關于ASP .NET CORE 2.2 JWT &amp;聲明網站身份認證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                    <tfoot id='fLBeL'></tfoot>

                          • <bdo id='fLBeL'></bdo><ul id='fLBeL'></ul>
                              <tbody id='fLBeL'></tbody>

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

                            <i id='fLBeL'><tr id='fLBeL'><dt id='fLBeL'><q id='fLBeL'><span id='fLBeL'><b id='fLBeL'><form id='fLBeL'><ins id='fLBeL'></ins><ul id='fLBeL'></ul><sub id='fLBeL'></sub></form><legend id='fLBeL'></legend><bdo id='fLBeL'><pre id='fLBeL'><center id='fLBeL'></center></pre></bdo></b><th id='fLBeL'></th></span></q></dt></tr></i><div class="idqrptm" id='fLBeL'><tfoot id='fLBeL'></tfoot><dl id='fLBeL'><fieldset id='fLBeL'></fieldset></dl></div>
                          • <legend id='fLBeL'><style id='fLBeL'><dir id='fLBeL'><q id='fLBeL'></q></dir></style></legend>
                            主站蜘蛛池模板: 小港信息港-鹤壁信息港 鹤壁老百姓便民生活信息网站 | 青岛美佳乐清洁工程有限公司|青岛油烟管道清洗|酒店|企事业单位|学校工厂厨房|青岛油烟管道清洗 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | 运动木地板厂家,篮球场木地板品牌,体育场馆木地板安装 - 欧氏运动地板 | 尚为传动-专业高精密蜗轮蜗杆,双导程蜗轮蜗杆,蜗轮蜗杆减速机,蜗杆减速机生产厂家 | 专业生物有机肥造粒机,粉状有机肥生产线,槽式翻堆机厂家-郑州华之强重工科技有限公司 | 寮步纸箱厂_东莞纸箱厂 _东莞纸箱加工厂-东莞市寮步恒辉纸制品厂 | 高压无油空压机_无油水润滑空压机_水润滑无油螺杆空压机_无油空压机厂家-科普柯超滤(广东)节能科技有限公司 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 数控专用机床,专用机床,自动线,组合机床,动力头,自动化加工生产线,江苏海鑫机床有限公司 | 带锯机|木工带锯机圆木推台锯|跑车带锯机|河北茂业机械制造有限公司| | 建大仁科-温湿度变送器|温湿度传感器|温湿度记录仪_厂家_价格-山东仁科 | 垃圾压缩设备_垃圾处理设备_智能移动式垃圾压缩设备--山东明莱环保设备有限公司 | 海鲜池-专注海鲜鱼缸、移动海鲜缸、饭店鱼缸设计定做-日晟水族厂家 | 超声骨密度仪,双能X射线骨密度仪【起草单位】,骨密度检测仪厂家 - 品源医疗(江苏)有限公司 | 宁波普瑞思邻苯二甲酸盐检测仪,ROHS2.0检测设备,ROHS2.0测试仪厂家 | 菲希尔FISCHER测厚仪-铁素体检测仪-上海吉馨实业发展有限公司 | 扒渣机厂家_扒渣机价格_矿用扒渣机_铣挖机_撬毛台车_襄阳永力通扒渣机公司 | 安全,主动,被动,柔性,山体滑坡,sns,钢丝绳,边坡,防护网,护栏网,围栏,栏杆,栅栏,厂家 - 护栏网防护网生产厂家 | 过跨车_过跨电瓶车_过跨转运车_横移电动平车_厂区转运车_无轨转运车 | 伶俐嫂培训学校_月嫂培训班在哪里报名学费是多少_月嫂免费政府培训中心推荐 | 齿轮减速机_齿轮减速电机-VEMT蜗轮蜗杆减速机马达生产厂家瓦玛特传动瑞环机电 | 杭州双螺杆挤出机-百科| 珠海冷却塔降噪维修_冷却塔改造报价_凉水塔风机维修厂家- 广东康明节能空调有限公司 | 智成电子深圳tdk一级代理-提供TDK电容电感贴片蜂鸣器磁芯lambda电源代理经销,TDK代理商有哪些TDK一级代理商排名查询。-深圳tdk一级代理 | wika威卡压力表-wika压力变送器-德国wika代理-威卡总代-北京博朗宁科技 | 西宁装修_西宁装修公司-西宁业之峰装饰-青海业之峰墅级装饰设计公司【官网】 | 济南网站策划设计_自适应网站制作_H5企业网站搭建_济南外贸网站制作公司_锐尚 | 整车VOC采样环境舱-甲醛VOC预处理舱-多舱法VOC检测环境仓-上海科绿特科技仪器有限公司 | 西安烟道厂家_排气道厂家_包立管厂家「陕西西安」推荐西安天宇烟道 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 锤式粉碎机,医药粉碎机,锥式粉碎机-无锡市迪麦森机械制造有限公司 | 撕碎机_轮胎破碎机_粉碎机_回收生产线厂家_东莞华达机械有限公司 | 横河变送器-横河压力变送器-EJA变送器-EJA压力变送器-「泉蕴仪表」 | 金联宇电缆总代理-金联宇集团-广东金联宇电缆实业有限公司 | 高扬程排污泵_隔膜泵_磁力泵_节能自吸离心水泵厂家-【上海博洋】 | 济南办公室装修-厂房装修-商铺装修-工装公司-山东鲁工装饰设计 | 企典软件一站式企业管理平台,可私有、本地化部署!在线CRM客户关系管理系统|移动办公OA管理系统|HR人事管理系统|人力 | 山东艾德实业有限公司| 外观设计_设备外观设计_外观设计公司_产品外观设计_机械设备外观设计_东莞工业设计公司-意品深蓝 | 新密高铝耐火砖,轻质保温砖价格,浇注料厂家直销-郑州荣盛窑炉耐火材料有限公司 | 时代北利离心机,实验室离心机,医用离心机,低速离心机DT5-2,美国SKC采样泵-上海京工实业有限公司 工业电炉,台车式电炉_厂家-淄博申华工业电炉有限公司 |