Answer the question
In order to leave comments, you need to log in
Using ASP.NET Identity in a three-tier architecture. How to change CookieAuthenticationProvider?
I use a three-tier architecture and ASP.NET Identity. I used a guide with metanit: metanit.com/sharp/mvc5/23.10.php
The problem is that I would like to add my CookieAuthenticationProvider to UseCookieAuthentication in the Startup mvc project.
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, int>
(TimeSpan.FromMinutes(30), async (manager, user) =>
{
var userIdentity = await manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
//userIdentity.AddClaim(new Claim("FriendlyName", friendlyName));
//userIdentity.AddClaim(new Claim("balance", balance.ToString(CultureInfo.CurrentCulture)));
//userIdentity.AddClaim(new Claim("sms", sms.ToString()));
//userIdentity.AddClaim(new Claim("minutes", minutes.ToString()));
return userIdentity;
}, id => id.GetUserId<int>())
}
Answer the question
In order to leave comments, you need to log in
So far, I've solved the problem in a different way.
1) Transferred ApplicationRoleManager, ApplicationSignInManager, ApplicationUserManager from DAL to BLL where they should have been, as I understand it, while leaving UserStore and RoleStore in DAl in UnitOfWork.
2) Created 2 static methods in ApplicationSignInManager
public static Func<CookieValidateIdentityContext, Task> OnValidateIdentity()
{
return SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, int>(TimeSpan.FromMinutes(30), GetIdentityAsync, id => id.GetUserId<int>());
}
public static async Task<ClaimsIdentity> GetIdentityAsync(ApplicationUserManager manager, ApplicationUser user)
{
var userIdentity = await manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
//userIdentity.AddClaim(new Claim("FriendlyName", friendlyName));
//userIdentity.AddClaim(new Claim("balance", balance.ToString(CultureInfo.CurrentCulture)));
//userIdentity.AddClaim(new Claim("sms", sms.ToString()));
//userIdentity.AddClaim(new Claim("minutes", minutes.ToString()));
return userIdentity;
}
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = ApplicationSignInManager.OnValidateIdentity()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question