MVC项目同时启用Cookie认证和ASP.NET身份认证

Enabling both Cookie authentication and ASP.NET Identity authentication in an MVC project

我有一个 MVC 站点,其中包含使用 cookie 身份验证的 MVC 控制器和 WebApi 控制器。但是,我希望某些 WebApi 控制器使用 Identity 3 服务器进行身份验证。我检查了这个答案,但 属性 AuthenticationScheme 不可用可能是因为我使用的是 Identity 3(或者它可能是 .NET 核心的一部分,我目前没有使用它)。

How do I issue the corresponding Bearer and Cookie identity in ASP.NET with multiple Authorization schemes?

我如何告诉某些 WebApi 控制器针对 Identity 3 服务器进行身份验证?

想通了,这可以使用方法 app.Map 并在其中指示路径和身份验证方法。像

        app.Map("/mobile", idsrvApp =>
        {
            idsrvApp.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
               ...
            });
        });

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
         ...
        });