MVC Forms LoginUrl is incorrect

前端 未结 8 885
旧时难觅i
旧时难觅i 2020-11-30 07:07

I have an ASP.NET MVC 3 application with forms authentication. For some reason that I cannot see, the login redirect url is /Account/Login?ReturnUrl=%2fSecure%2fAction

8条回答
  •  失恋的感觉
    2020-11-30 08:09

    I just ran into this issue (like 6 years later and this page doesn't rank high in searches anymore...) my fix was similar to santiagoIT.

    Because I added authentication to a project that didn't previously have it I pretty much "cheated" by copying required authentication code from a default project template which included:

    app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"), 
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
    

    The forms authentication url was using web.config for all my aspx pages but bombed when I added the Authorize attribute.

    Changing the LoginPath fixed my issue.

提交回复
热议问题