ASP.NET MVC 5:无尽重定向到与使用网站模板的登录页面 [英] ASP.NET MVC 5 : Endless redirect to the login page using the site template

查看:452
本文介绍了ASP.NET MVC 5:无尽重定向到与使用网站模板的登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是用ASP.NET MVC 5开始(我已经使用了previous版本颇多),我有一个很奇怪的问题:我创建了使用Visual Studio 2013(完全更新),ASP一个新的网站。 NET模板。对于模板选项,我选择了MVC的模板,个人用户帐户身份验证类型,无云托管,并没有其他的组件比核心MVC库。之后,我验证的选项,我更新所有的Nu​​Get包。而且我preSS F5后(不打开或修改任何新的项目文件)。

浏览器只打开显示,因为无限重定向循环的错误页面,:网址显示:

<$p$p><$c$c>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认证选项中定义,这看起来很不错:

  //配置在cookie中的标志
app.UseCookieAuthentication(新CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LOGINPATH =新PathString(/帐号/登录),
    供应商=新CookieAuthenticationProvider
    {
        //允许应用验证安全戳当用户登录英寸
        //这是一项安全功能,当您更改密码或添加外部登录到您的帐户被使用。
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity&LT; ApplicationUserManager,ApplicationUser&GT;(
            validateInterval:TimeSpan.FromMinutes(30),
            regenerateIdentity:(经理,用户)=&GT; user.GenerateUserIdentityAsync(经理))
    }
});

这也许可以打破默认网站的唯一的东西就是在全球的web.config / machine.config中的文件,虽然我通常避免与他们对我开发框搞乱。启动模板没有更新的NuGet包不能解决问题。有可能出错了ASP.NET的身份lib中,但我真的不知道,我无法找到与我的问题的任何相关信息。

问:有谁知道是什么问题,或者至少是对解决此最好的办法

感谢


解决方案

好了,所以后一个良好的睡眠我最终找到了什么问题:问题是在IIS防爆preSS的配置,这是不重置一些原因,当我创建了一个新的项目,也可能继承了previous项目的设置。它有匿名身份验证禁用和启用Windows身份验证,这是不符合由模板创建的默认的web.config兼容的,因为它有身份验证模式设置为。因此,IIS期待一个Windows身份验证的任何资源供应前,网站没有要求Windows凭据。还有我们有一个无限循环。

TL; DR如果您有同样的问题,检查项目属性(请在Solution Explorer中的项目,preSS F4)。在匿名身份验证项应设置为已启用 Windows身份验证项应设置为禁用。请注意,这是唯一有效的,如果你没有在模板设置中选择Windows身份验证!

I just started using ASP.NET MVC 5 (I already used the previous versions quite a lot) and I have a very weird issue: I created a new website using the Visual Studio 2013 (fully updated) ASP.NET template. For the template options I selected the MVC template, "Individual User Accounts" authentication type, no cloud hosting, and no other components than the core MVC library. After I validate the options, I update all the NuGet packages. And after that I press F5 (without opening or modifying any of the new project files).

The browser opens only to show an error page, because of an endless redirection loop: the 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 stock, unmodified ASP.NET MVC template. I did check that the login URL is defined in the cookie auth options, and that 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 could maybe break the default website is something in the global web.config/machine.config files, although I usually avoid messing with them on my dev box. Launching the template without updating the NuGet packages does not solve the issue. There's probably something wrong with the ASP.NET Identity lib, but I don't really know it and I couldn't find any relevant info related to my issue.

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

Thanks

解决方案

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 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 !

这篇关于ASP.NET MVC 5:无尽重定向到与使用网站模板的登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆