gpt4 book ai didi

asp.net-mvc - ASP.NET MVC 5 : Endless redirect to the login page using the site template

转载 作者:行者123 更新时间:2023-12-04 10:24:48 26 4
gpt4 key购买 nike

我刚开始使用 ASP.NET MVC 5(我已经使用了很多以前的版本),我有一个非常奇怪的问题:我使用 Visual Studio 2013(完全更新)ASP.NET 模板创建了一个新网站。对于模板选项,我选择了 MVC 模板,“个人用户帐户”身份验证类型,没有云托管,除了核心 MVC 库之外没有其他组件。验证选项后,我更新所有 NuGet 包。之后我按 F5(不打开或修改任何新项目文件)。

由于无限重定向循环,浏览器打开仅显示错误页面:URL 显示:

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

同样,这是使用未经修改的 ASP.NET MVC 模板。我确实检查了登录 URL 是否在 cookie auth 选项中定义,看起来不错:
// 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))
}
});

唯一可能破坏默认网站的是全局 web.config/machine.config 文件中的某些内容,尽管我通常会避免在我的开发箱上弄乱它们。在不更新 NuGet 包的情况下启动模板并不能解决问题。 ASP.NET Identity 库可能有问题,但我真的不知道,也找不到与我的问题相关的任何信息。

问题:有谁知道问题是什么,或者至少解决此问题的最佳方法是什么?

谢谢

最佳答案

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

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

关于asp.net-mvc - ASP.NET MVC 5 : Endless redirect to the login page using the site template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26064668/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com