I am using the below code for authentication in ASP.NET Core 2.0 using cookies
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie("MyCookieMiddlewareInstance", options =>
{
options.AccessDeniedPath = new PathString("/Account/Login");
options.LoginPath = new PathString("/Account/Login");
options.LogoutPath = new PathString("/Account/LogOff");
});
I am getting an error:
No authenticationScheme was specified, and there was no DefaultChallengeScheme found
The cookies setup is below:
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, userId.ToString()),
new Claim(ClaimTypes.Name, userName)
};
var identity = new ClaimsIdentity(claims, "Forms");
identity.AddClaim(new Claim(ClaimTypes.Role, "ADMIN"));
var principal = new ClaimsPrincipal(identity);
HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal, new AuthenticationProperties
{
IsPersistent = isPersistent,
ExpiresUtc = DateTime.UtcNow.AddYears(1)
});
I did some research and didn't find the solution. Here is a link to the doc I used:
Can anyone please let me know how can I resolve this issue?