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

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

  1. <tfoot id='VbIkd'></tfoot>
      <bdo id='VbIkd'></bdo><ul id='VbIkd'></ul>
    <legend id='VbIkd'><style id='VbIkd'><dir id='VbIkd'><q id='VbIkd'></q></dir></style></legend>

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

      添加 Authorize 屬性時 Web api 核心返回 404

      Web api core returns 404 when adding Authorize attribute(添加 Authorize 屬性時 Web api 核心返回 404)
      <i id='2YS2d'><tr id='2YS2d'><dt id='2YS2d'><q id='2YS2d'><span id='2YS2d'><b id='2YS2d'><form id='2YS2d'><ins id='2YS2d'></ins><ul id='2YS2d'></ul><sub id='2YS2d'></sub></form><legend id='2YS2d'></legend><bdo id='2YS2d'><pre id='2YS2d'><center id='2YS2d'></center></pre></bdo></b><th id='2YS2d'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2YS2d'><tfoot id='2YS2d'></tfoot><dl id='2YS2d'><fieldset id='2YS2d'></fieldset></dl></div>
    2. <tfoot id='2YS2d'></tfoot>
      <legend id='2YS2d'><style id='2YS2d'><dir id='2YS2d'><q id='2YS2d'></q></dir></style></legend>
        <tbody id='2YS2d'></tbody>

            <bdo id='2YS2d'></bdo><ul id='2YS2d'></ul>

            1. <small id='2YS2d'></small><noframes id='2YS2d'>

              • 本文介紹了添加 Authorize 屬性時 Web api 核心返回 404的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我是 .net 核心的新手,我正在嘗試創建實現 jwt 以進行身份??驗證和授權的 web api 核心.

                I am new to .net core, and I am trying to create web api core which implements jwt for authentication and authorization purposes.

                在 Startup 類中我是這樣配置的:

                Inside Startup class I configured it this way:

                public class Startup
                {
                    public Startup(IConfiguration configuration)
                    {
                        Configuration = configuration;
                    }
                
                    public IConfiguration Configuration { get; }
                
                    // This method gets called by the runtime. Use this method to add services to the container.
                    public void ConfigureServices(IServiceCollection services)
                    {
                
                        services.AddDbContext<MandarinDBContext>(options =>
                            options.UseSqlServer(Configuration.GetConnectionString("MyConnection")));
                
                        services.AddIdentity<User, Role>()
                        .AddEntityFrameworkStores<MyDBContext>()
                        .AddDefaultTokenProviders();
                
                        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                                .AddJwtBearer(options =>
                                {
                                    options.TokenValidationParameters = new TokenValidationParameters
                                    {
                                        ValidateIssuer = false,
                                        ValidateAudience = false,
                                        ValidateLifetime = true,
                                        ValidateIssuerSigningKey = true,
                                        ValidIssuer = "yourdomain.com",
                                        ValidAudience = "yourdomain.com",
                                        IssuerSigningKey = new SymmetricSecurityKey(
                                            Encoding.UTF8.GetBytes("My secret goes here"))
                                    };
                
                                    options.RequireHttpsMetadata = false;
                                });
                
                        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
                
                        // Add application services.
                        services.AddTransient<IUserService, UserService>();
                    }
                
                    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
                    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
                    {
                        if (env.IsDevelopment())
                        {
                            app.UseDeveloperExceptionPage();
                        }
                        else
                        {
                            app.UseHsts();
                        }
                
                        app.UseHttpsRedirection();
                
                        app.UseAuthentication();
                        app.UseMvc();
                    }
                }
                

                但是當我嘗試調用以下操作時:

                But when I try to call the following action:

                    [Authorize]
                    [HttpGet]
                    [Route("api/Tokens")]
                    public IActionResult TestAuthorization()
                    {
                        return Ok("You're Authorized");
                    }
                

                我得到 404 未找到.如果我刪除 Authorize 屬性它正在工作.

                I get 404 not found. If I remove Authorize attribute it's working .

                你能指導我解決這個問題嗎?

                Could you please guide me to solve that issue?

                推薦答案

                當您的 API 未經授權且您的重定向 URL 不存在時會發生這種情況.當身份驗證失敗時,Web API 將發送一個 401 代碼.現在,如果您在客戶端處理此代碼并為授權失敗執行重定向,請確保重定向的 Url 存在.此外,請勿將 [Authorize] 屬性添加到處理身份驗證方法(登錄/注冊)的控制器.您的罪魁禍首似乎是 Authorize 屬性.由于您使用的是 JWT 身份驗證方案.您的授權屬性應遵循

                It happens when your API is not authorized and your redirect URL doesn't exist. When authentication fails, Web API will send a 401 code. Now if you are handling this code on the client side and doing a redirect for an authorization failure, then make sure that the redirected Url exists. Also, Do not add the [Authorize] attribute to the controller that handles Authentication methods (Login/Register). Your culprit looks to be the Authorize attribute. Since you are using JWT authentication scheme. Your authorize attribute should be following

                    [Authorize(AuthenticationSchemes = "Bearer")]
                    [HttpGet]
                    [Route("api/Tokens")]
                    public IActionResult TestAuthorization()
                    {
                        return Ok("You're Authorized");
                    }
                

                要使其成為默認身份驗證方案,請將 AddIdentity 更改為 AddIdentityCore.這是一篇非常好的文章.

                To make it default authentication scheme, Change AddIdentity to AddIdentityCore. here is a very good article.

                在僅 API 的 ASP.NET Core 項目中使用 JwtBearer 身份驗證

                這篇關于添加 Authorize 屬性時 Web api 核心返回 404的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

                        <tbody id='5rj4k'></tbody>

                        <small id='5rj4k'></small><noframes id='5rj4k'>

                        • <bdo id='5rj4k'></bdo><ul id='5rj4k'></ul>
                        • <tfoot id='5rj4k'></tfoot>
                          <i id='5rj4k'><tr id='5rj4k'><dt id='5rj4k'><q id='5rj4k'><span id='5rj4k'><b id='5rj4k'><form id='5rj4k'><ins id='5rj4k'></ins><ul id='5rj4k'></ul><sub id='5rj4k'></sub></form><legend id='5rj4k'></legend><bdo id='5rj4k'><pre id='5rj4k'><center id='5rj4k'></center></pre></bdo></b><th id='5rj4k'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5rj4k'><tfoot id='5rj4k'></tfoot><dl id='5rj4k'><fieldset id='5rj4k'></fieldset></dl></div>
                          <legend id='5rj4k'><style id='5rj4k'><dir id='5rj4k'><q id='5rj4k'></q></dir></style></legend>
                          主站蜘蛛池模板: 欧美高清dvd | 亚洲成人免费电影 | 91精品国产日韩91久久久久久 | 国产一级免费在线观看 | 欧美电影在线观看网站 | 日韩精品在线网站 | 中文字幕免费在线 | 久久97精品| 黄色大片在线免费观看 | 欧美一区二区三区在线看 | 久久aⅴ乱码一区二区三区 91综合网 | 成人午夜免费视频 | 日韩电影在线一区 | 色吊丝在线 | 日韩精品在线播放 | 欧美国产激情二区三区 | 色综合天天综合网国产成人网 | 久久97精品 | 精品欧美乱码久久久久久 | 亚洲精品久久久久中文字幕欢迎你 | 精品成人在线视频 | 嫩草视频在线看 | 国产a视频 | 91精品国产一区二区三区 | 人人草天天草 | 999久久久久久久久6666 | 久久国产精品一区二区三区 | 久久88 | 亚洲国产成人精品久久久国产成人一区 | www亚洲精品 | 欧美最猛性xxxxx亚洲精品 | 中文字幕福利视频 | 亚洲伊人精品酒店 | 成人一区二区三区在线 | 亚洲一区二区三区视频免费观看 | 色综合一区 | 成人在线国产 | 欧美黄色一区 | 一区二区三区国产精品 | 亚洲一av | 久久免费国产视频 |