2

Startup.cs:

        app.UseCookieAuthentication(new CookieAuthenticationOptions()
        {
            AuthenticationScheme = "CustomAuthenticationCookieMiddleware",
            LoginPath = new PathString("/user/login"),
            LogoutPath = new PathString("/user/logout"),
            AccessDeniedPath = new PathString("/access-denied"),
            AutomaticAuthenticate = true,
            AutomaticChallenge = true
        });

MembershipController.cs

...
await HttpContext.Authentication.SignInAsync("CustomAuthenticationCookieMiddleware", claimsPrincipal, new AuthenticationProperties { IsPersistent = loginUser.RememberMe });
...

========

問題:

[Authorize]属性が機能しません。アクセス拒否ページにリダイレクトします。

しかし [Authorize(Roles = "Administrator")]、非常にうまく機能します

注: "User.Identity.IsAuthenticated"ログインに成功しても常にfalseです

4

1 に答える 1