Reputation: 617
I am attempting to add ASP.NET Identity 3.0 single user authentication to the "ASP.NET Core Application Angular template" within Visual Studio 2017. I have created a GitHub repository here:
https://github.com/DapperDanH/NutmegStackoverflow
There really is not much to this project yet. From a high level, this is what i did:
My goal is to use standard ASP.NET MVC for the authentication portions.
Everything appears to work. The web application launches and shows the home page. I created links to "Register" and "Login" pages. I can successfully register a new user and the new user is added to the database. The user can enter their information in the Login page, and the AccountController.Login method returns success to the PasswordSignInAsync method:
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);
The issue is, no auth cookie is created. Well, about 99% of the time a cookie is NOT created but every now and then one is created.
My gut says the issue may be in the Startup.cs. Here is the code I am using:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<NutmegContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<User, AppRole>()
.AddEntityFrameworkStores<NutmegContext>()
.AddDefaultTokenProviders();
// Add application services.
services.AddTransient<IEmailSender, EmailSender>();
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true
});
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
}
I really hope someone can help me. To see this in action:
Hoping someone can help me out. Thanks for reading this long post!
Thanks, Dan
Upvotes: 0
Views: 698
Reputation: 617
I was able to get the application to consistently create the auth cookie but switching my web project to HTTPS. I have no clue why that would matter, but it seems to fix it. anyone able to explain?
Upvotes: 1