在MVC项目中启用Cookie身份验证和ASP.NET身份验证

时间:2017-09-28 18:00:27

标签: asp.net-mvc asp.net-web-api asp.net-identity-3

我有一个MVC站点,包含MVC控制器和使用cookie身份验证的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服务器进行身份验证?

1 个答案:

答案 0 :(得分:0)

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

这样的东西
        app.Map("/mobile", idsrvApp =>
        {
            idsrvApp.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
               ...
            });
        });

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