Click here to Skip to main content
14,691,039 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to create a simple ASP.NET Core based login without the use of databases. Lets say instead of using a database, I have the login UserName and Password in the appsettings.json. I could easily access and get the appsettings values. But how should I go about implementing the login functionality and how should I configure services in the startup.cs (in Configure and ConfigureServices).

In Configure() method I have added the

When I login and move to the Controller class which uses the annotation
I get the following error:

An unhandled exception occurred while processing the request.
InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action<AuthenticationOptions> configureOptions).
Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties)

Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

What I have tried:

In Configure() method I have added the
Updated 8-Mar-20 0:09am
Richard MacCutchan 4-Mar-20 4:32am
You need to do what the error message is telling you.
Richard Deeming 4-Mar-20 10:23am
Make sure you're not storing the passwords in plain text:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

1 solution

In Startup.Configure, call UseAuthentication and UseAuthorization to set the HttpContext.User property and run Authorization Middleware for requests. Call the UseAuthentication and UseAuthorization methods before calling UseEndpoints:


app.UseEndpoints(endpoints =>

Set CookieAuthenticationOptions in the service configuration for authentication in the Startup.ConfigureServices method:

    .AddCookie(options =>

Sign In
You'll have to create your claims and pass while creating claims identity and set Authentication Scheme

var claims = new List<Claim>
    new Claim(ClaimTypes.Name, user.Email),
    new Claim("LastChanged", {Your Value})

var claimsIdentity = new ClaimsIdentity(

await HttpContext.SignInAsync(
    new ClaimsPrincipal(claimsIdentity));

Sign Out

await HttpContext.SignOutAsync(

For more details please read this article
Use cookie authentication without ASP.NET Core Identity | Microsoft Docs[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900