On startup.cs on Configure I have:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies",
LoginPath = new PathString("/Account/Login/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
On normal controller:
[Authorize]
public class HomeController : Controller
{
public IActionResult Index() { return View(); }
}
On AccountController:
public class AccountController : Controller
{
[AllowAnonymous]
public IActionResult Login() { return View(); }
}
Accessing Home/Index, unauthenticated, should redirect to login, but returns blank page. I receive 401 on fiddler, but pages does not redirect. It seems like nothing`s wrong, but still does not work. Does anyone know why?
You are experiencing issue with AutomaticChallenge option. This option is causing a conflict between IISIntegration and Cookie middleware, see detailed notes here .
If you are using [Authorize], the solution would be to add the following code to your startup.cs inside ConfigureServices(IServiceCollection services)
services.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder("Cookies").RequireAuthenticatedUser().Build();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.