我已经实现了自己的自定义身份验证中间件和处理程序,并在应用启动时配置了它们.这一切都很好.
在我的自定义auth处理程序中,我已经覆盖了HandleAuthenticateAsync()以执行我自己的自定义身份验证,我还重写了HandleUnauthorizedAsync()以便将用户重定向到登录页面,但是这不会被调用.
浏览器在响应中收到401(未授权).我期待调用我的HandleUnauthorizedAsync().
我在这里没有正确理解管道吗?
谢谢
我有一个使用基本身份验证的 ASP.NET Core 2.2 Web API。到目前为止,它运行良好,没有任何问题。在其中一个控制器中[AllowAnonymous],像往常一样装饰一个操作方法以进行用户登录。
[Produces("application/json")]
[Route("user")]
[AllowAnonymous]
[ApiController]
public class LoginController : ControllerBase
{
private readonly IConfiguration _configuration;
private readonly IMessagingService _messageService;
private readonly IBasicAuthenticationService _basicAuthenticationService;
private readonly string PWAPIBaseUrl;
public LoginController(IConfiguration configuration, ILogger<LoginController> logger, IMessagingService messagingService, IBasicAuthenticationService authenticationService)
{
_configuration = configuration;
_logger = logger;
_messageService = messagingService;
_basicAuthenticationService = authenticationService;
}
[HttpGet]
[AllowAnonymous]
[Route("login/{username}/{clientID}")]
public async Task<IActionResult> UserLogin(string username, string clientID)
{
// Check the Credentials Manually
string failReason = "";
if (!CheckCredentials(out failReason)) …Run Code Online (Sandbox Code Playgroud) c# authentication authorization asp.net-core asp.net-core-webapi
我已经在我的应用程序的 API 部分实现了 JWT 身份验证/授权。我还有一个 ASP.NET core MVC 网站,我想对其进行身份验证。是否可以使用 API 中的 JWT 令牌对网站进行身份验证?我想阻止用户前往特定位置,除非获得授权,否则重定向到登录页面。我发现的所有示例都展示了如何使用 API (JWT) 或 MVC 网站 (cookie) 执行此操作,但不能同时使用两者。