A
A
Andrew2016-05-15 19:59:59
ASP.NET
Andrew, 2016-05-15 19:59:59

Why is ASP NET Identity returning 401 instead of redirecting to LoginPath?

I'm trying to add ASP NET Identity to an existing MVC5 project. Code first is used, everything is ready, the tables with users, roles, etc. were generated and filled with the necessary roles and users specified in Seed.
Here is my Startup.cs, which, in theory, starts the authorization process

[assembly: OwinStartupAttribute(typeof(CarWashApplication.Startup))]
namespace CwProject
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
        public void ConfigureAuth(IAppBuilder app)
        {
            app.CreatePerOwinContext(CwDb.Create);
            app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
            
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
            });
        }
    }
}

I made authorization in the image and likeness of authorization from the project, which is generated by the studio when creating a new project.
I add authorization through an attribute, for example [Authorize(Roles = "Manager")]
Authorization is needed only locally, without any third-party services and two factors.
Maybe I forgot to add something somewhere to make the authorization work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2016-05-18
@byte916

I found a solution. I just added the Microsoft.Owin.Host.SystemWeb library to the project and it worked. It's strange that none of the solutions and instructions "how to start using identity" contained a word about this library.

#
#algooptimize #bottize, 2016-05-17
@user004

https://github.com/aspnet/Security/issues/607

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question