ASP.NET MVC 5: Infinite redirect to login page using site template

I just started using ASP.NET MVC 5 (I have used quite a lot of previous versions) and I have a very strange problem: I created a new website using the ASP.NET Visual Studio 2013 template (completely updated). For the template parameters, I chose the MVC template, the authentication type "Individual user accounts", cloud hosting and other components except the main MVC library. After checking the settings, I update all the NuGet packages. And after that I press F5 (without opening or changing any new project files).

The browser only opens to display an error page due to an infinite redirect cycle: URL shows:

http://localhost:24585/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%252525<snip> 

Again, this is with the unmodified ASP.NET MVC pattern. I really checked that the login url is defined in the auth cookie options and this looks good:

 // Configure the sign in cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { // Enables the application to validate the security stamp when the user logs in. // This is a security feature which is used when you change a password or add an external login to your account. OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); 

The only thing that can break the default website is something in the global web.config / machine.config files, although I usually avoid talking to them in my dev block. Running the template without updating the NuGet packages does not solve the problem. There is probably something wrong with the ASP.NET Identity, but I do not know this, and I could not find any relevant information related to my problem.

Question: Does anyone know what the problem is, or at least the best way to fix this problem?

thanks

+5
source share
1 answer

So, after a good night’s sleep, I realized that it wasn’t: the problem was in the IIS Express configuration, which was not reset for some reason, when I created a new project and probably inherited the previous project settings. It has disabled anonymous authentication and enabled Windows authentication, which is not compatible with the standard web.config created by the template, because the authentication mode is set to None . Thus, IIS was waiting for Windows authentication before any resource was served, and the website did not request Windows credentials. And there we have an endless cycle.

TL DR If you have the same problem, check the project properties (select the project in the solution explorer and press F4). The Anonymous Authentication entry must be set to Enabled , and the Windows Authentication entry must be set to Disabled . Please note that this is only valid if you did not select Windows authentication in the template settings!

+10
source

Source: https://habr.com/ru/post/1203494/


All Articles