且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC 5:使用站点模板无限重定向到登录页面

更新时间:2023-02-24 22:49:44

好的,经过一夜好眠后,我终于发现了问题所在:问题出在 IIS Express 配置中,在我创建时由于某种原因没有重置一个新项目,并且可能继承了以前项目的设置.它禁用了匿名身份验证并启用了 Windows 身份验证,这与模板创建的默认 web.config 不兼容,因为它的身份验证模式设置为 None.因此,IIS 期望在提供任何资源之前进行 Windows 身份验证,并且该网站没有要求提供 Windows 凭据.我们有一个无限循环.

Ok so after a good night's sleep I ended up finding what's wrong: the problem was in the IIS Express configuration, which was not reset for some reason when I created a new project, and probably inherited a previous project's settings. It had Anonymous Authentication disabled and Windows Authentication enabled, which is not compatible with the default web.config created by the template, since it had authentication mode set to None. So IIS was expecting a Windows authentication before any resource is served, and the website did not ask for Windows credentials. And there we have an infinite loop.

TL;DR 如果您遇到同样的问题,请检查项目属性(在解决方案资源管理器中选择项目,然后按 F4).Anonymous Authentication 条目应设置为 EnabledWindows Authentication 条目应设置为 Disabled.请注意,这仅在您未在模板设置中选择 Windows 身份验证时才有效!

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