使用端点时,ASP.NET Core(3.0)上的身份不起作用

问题描述 投票:0回答:1
  • 当我使用路由时,身份运行正常。
  • 当我使用端点时,用户被困在LogIn视图中(任何访问以[Authorize]装饰的Action方法的尝试都会重定向到我的LogIn界面,即使SignInResult成功后也是如此。]]

    //Identity functions as expected:
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "areas",
            template: "{area:exists}/{controller=Home}/{action=Index}");
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
    
  • 但是:

// Identity not functioning when using endpoints:
app.UseEndpoints(endpoints =>
{
    endpoints.MapHub<ChatHub>("/chatHub");
    endpoints.MapControllerRoute(
        name: "areas",
        pattern: "{area:exists}/{controller=Home}/{action=Index}");
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
});

应用程序的其余部分可以使用端点正常运行,我的问题仅在于身份。

当我使用路由时,身份运行正常。当我使用端点时,用户会停留在LogIn视图中(任何访问以[Authorize]装饰的Action方法的尝试都将重定向到我的LogIn ...

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

如果该应用使用身份验证/授权功能,例如AuthorizePage[Authorize],将呼叫转到UseAuthentication,然后UseAuthorization:在UseRoutingUseCors之后,但之前UseEndpoints

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