简体   繁体   English

Asp.net核心Cookie身份验证请求过多

[英]Asp.net core cookie authentication too many requests

I am following Cookie Middleware to add authentication for my simple web application. 我正在使用Cookie中间件来为我的简单Web应用程序添加身份验证。

I have added the below code in startup.cs Configure method. 我在startup.cs Configure方法中添加了以下代码。

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationScheme = "Cookies",
    LoginPath = new PathString("/Account/Login/"),
    AccessDeniedPath = new PathString("/Account/Error/"),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});

When i accessing /Home, it redirects to /Account/Login but page doesn't open and getting error message as 当我访问/ Home时,它重定向到/ Account / Login,但是页面无法打开,并且显示错误消息为

The localhost page isn't working : localhost redirected you too many times. 本地主机页面不起作用:本地主机重定向您太​​多次。

The url appends with same login page many times and look like 网址多次附加到同一登录页面,看起来像

http://localhost:5000/Account/Login/?ReturnUrl=%2FAccount%2FLogin%2F%3FReturnUrl%3D%252FAccount%252FLogin%252F%253FReturnUrl%253D%25252FAccount........%2FHome http:// localhost:5000 / Account / Login /?ReturnUrl =%2FAccount%2FLogin%2F%3FReturnUrl%3D%252FAccount%252FLogin%252F%253FReturnUrl%253D%25252FAccount ........%2FHome

What i did wrong? 我做错了什么? Help me to solve this. 帮我解决这个问题。

This is because your /Account/Login action also requires login, which causes an infinite redirect loop. 这是因为您的/Account/Login操作还需要登录,这会导致无限重定向循环。 Add AllowAnonymousAttribute on this action. 在此操作上添加AllowAnonymousAttribute

In my case the /Account/Login controller already has the AllowAnonymous attribute but I keep getting the message 在我的情况下, /Account/Login控制器已经具有AllowAnonymous属性,但我一直收到消息

The localhost page isn't working : localhost redirected you too many times. 本地主机页面不起作用:本地主机重定向您太​​多次。

The problem was in the IIS configuration. 问题出在IIS配置中。 I had to change some options in the authentication tab. 我必须更改身份验证选项卡中的某些选项。 I had to disable the Windows Authentication option and enable the Anonymous Authentication option. 我必须禁用Windows身份验证选项,然后启用匿名身份验证选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM