Answer the question
In order to leave comments, you need to log in
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"),
});
}
}
}
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question