asp net core web api return 401 whenne add Authorization header and call AllowAnonymous method how to ignore check Authentication for Anonymous method.

问题描述 投票:0回答:1

我在项目中使用了jwt,我有一系列的方法,这些方法都是通用的,但是由于某些原因,我需要在请求者的头中发送token,但是当发送token的时候,如果它的有效期过了,就会给出401的错误,根本就进入不了这个方法,这个方法没有Authorize过滤器,而这个问题,虽然根本就没有Route,但是如果头中有token,就会返回401。在到达Routing中间件之前,jwt OnAuthenticationFailed事件将其捕获 中间件的顺序也是观察到的 Net core项目3.邮递员

我的方法

c# .net jwt asp.net-core-webapi core
1个回答
0
投票

你需要用jwt使用claim来重新生成token。

如果是jQuery,你需要使用jQuery ajaxprefilter。它将在实际调用服务器端之前执行。

所以,如果token过期,ajaxprefilter会检查。

如果过期,调用aap.net核心中间件的要求,重新生成token。然后再进行原始调用。

© www.soinside.com 2019 - 2024. All rights reserved.