Let's suppose we have a web-site where there are:
- Admin section
- Client section
- Guest(visitor) section
Obviously, the last one (Guest section) can be accessed by everyone while admin part - only by administrations and client part - only by registered clients. Admins and clients have different model classes (Admin and User correspondingly), are stored in the different databases and we would like to use different authentication cookies for each of them. Is it possible to do with ASP.NET Core Identity?
We tried to use CookieName property during AddIdentity initialization but it appears that ApplicationCookie accessible there - is the same object, so the second definition simply rewrites the first one:
services
.AddIdentity<User, UserRole>(opts => {
opts.Cookies.ApplicationCookie.CookieName = "Client";
opts.Cookies.ApplicationCookie.LoginPath = new PathString("/login");
. . . . . .
});
services
.AddIdentity<Admin, AdminRole>(opts => {
//the following lines rewrite cookie options from client's to admin's
opts.Cookies.ApplicationCookie.CookieName = "Admin";
opts.Cookies.ApplicationCookie.LoginPath = new PathString("/admin/login");
. . . . . .
});