MVC 5 Redirect to Login Page Not Working with OWIN

♀尐吖头ヾ 提交于 2019-12-05 05:30:53

I’ve created two new similar projects and was able to reproduce your error.

In the blank project, I had to install the Microsoft.Owin.Host.SystemWeb (via Nuget) and once I did this, I was getting a bunch of errors in my Startup.cs class. Ended up with this:

[assembly: OwinStartupAttribute(typeof(v2.Startup))]
namespace v2
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }

        public void ConfigureAuth(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "ApplicationCookie",
                LoginPath = new PathString("/Account/Login")
            });
        }
    }
}

In the end, I'm now capable of hitting/seeing my Login view when I call the About() method decorated with the [Authorize] attribute.

Hope this helps! Vince

Aaron Sherman

Per ASP.NET MVC 5 Web.config: "FormsAuthenticationModule" or "FormsAuthentication"

<system.webServer>
    <modules>
      <remove name="FormsAuthentication" />
    </modules>
</system.webServer>

for extra safety I left both the "typo" handler in (in case Microsoft changes it later giving me)

<system.webServer>
    <modules>
     <remove name="FormsAuthenticationModule" />
     <remove name="FormsAuthentication" />
    </modules>
</system.webServer>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!