ASP.NET Core Identity by default uses cookies to store
claims. If your authorization is very granular then you will end up using many
claims. With all these claims stored in cookie, the cookie size gets bigger and
you can exceed the cookie limit.
We can achieve the authorization granularity without
exceeding the cookie limit and impacting the way ASP.NET Identity authorizes
users by storing the claims in session, Redis or any other memory storage.
Below are the steps I implemented to store the claims in
session.
First let’s store the claims in session (assuming that the
ASP.NET Core Session is already configured). During authentication, Identity
system uses SignInManager for creating principal object of the logged in user.
While creating the principal object, Identity populates the claims. We can
override this SignInManager and store the claims as shown below:
public class ApplicationSignInManager : SignInManager<ApplicationUser>
{
private IHttpContextAccessor contextAccessor;
public
ApplicationSignInManager(UserManager<ApplicationUser> userManager, IHttpContextAccessor contextAccessor, IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory, IOptions<IdentityOptions> optionsAccessor, ILogger<SignInManager<ApplicationUser>> logger)
: base(userManager,
contextAccessor, claimsFactory, optionsAccessor, logger)
{
this.contextAccessor =
contextAccessor;
}
public override async Task<ClaimsPrincipal>
CreateUserPrincipalAsync(ApplicationUser user)
{
var principal = await base.CreateUserPrincipalAsync(user);
ClaimsIdentity identity = (ClaimsIdentity)principal.Identity;
//
storing claims in session and removing them. These claims will be added by
Transformer
List<ClaimModel> sessionClaims = new List<ClaimModel>();
List<Claim> identityClaims =
identity.Claims.ToList();
foreach (var claim in identityClaims)
{
sessionClaims.Add(new ClaimModel() { ClaimType =
claim.Type, ClaimValue = claim.Value });
identity.RemoveClaim(claim);
}
this.contextAccessor.HttpContext.Session.SetString("IdentityClaims", JsonConvert.SerializeObject(sessionClaims));
return principal;
}
}
The Identity system should be configured to use our ApplicationSignInManager
instead of the default one. For this we need to define the dependency injection
in the Startup under ConfigureServices
services.AddScoped<SignInManager<ApplicationUser>, ApplicationSignInManager>();
As you see with above code claims are removed from the
principal identity and stored in the session. These claims should to be added
back to the principal identity for every request. This done through the claims transformer
as shown below:
public class ClaimsTransformer : IClaimsTransformer
{
public Task<ClaimsPrincipal> TransformAsync(ClaimsTransformationContext context)
{
ClaimsPrincipal principal =
context.Principal;
ClaimsIdentity identity = (ClaimsIdentity)principal.Identity;
string claimString = NTContext.HttpContext.Session.GetString("IdentityClaims");
if (claimString != null)
{
List<ClaimModel> sessionClaims = JsonConvert.DeserializeObject<List<ClaimModel>>(claimString);
identity.AddClaims(sessionClaims.Select(sc => new Claim(sc.ClaimType,
sc.ClaimValue)));
}
return Task.FromResult(principal);
}
}
This ClaimsTransformer class is
configured in the Startup under Configure section as shown below:
app.UseClaimsTransformation(new ClaimsTransformationOptions()
{
Transformer = new ClaimsTransformer(),
});
app.UseIdentity();
With the above setup now the claims are stored in session when
the user logs in. At every request from the user these claims will be copied
from session to the identity object. Now we have overridden the default
approach of using cookies with session J
Oh, they are really hard to distinguish from each other! Thanks for the help
ReplyDeleteThe saving all applications is optimal in each case. However, this also has a limit. The users will be able to leave their requests for review.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favourites blog site list and will be checking back soon.
ReplyDeleteClick here:
angularjs training in chennai
Click here:
angularjs2 training in chennai
A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts read this.
ReplyDeleteClick here:
Microsoft azure training in chennai
Click here:
Microsoft azure training in online
Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
ReplyDeleteDevops training in velachery
Devops training in annanagar
Fake IDs can be awesome fun as long as you utilize them legitimately. http://idhurry.com/ Numerous individuals imagine that fake ids are illicit, yet for the most part this isn't the situation.
ReplyDeleteA very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
ReplyDeleterpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune
It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
ReplyDeletejava training in jayanagar | java training in electronic city
java training in chennai | java training in USA
I think you have a long story to share and i am glad after long time finally you cam and shared your experience.
ReplyDeleteData Science course in Chennai | Data science course in bangalore
Data science course in pune | Data science online course
Data Science Interview questions and answers
Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
ReplyDeleteangularjs-Training in tambaram
angularjs-Training in sholinganallur
angularjs-Training in velachery
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.
ReplyDeleteAmazon Web Services Training in Pune | Best AWS Training in Pune
AWS Training in Pune | Best Amazon Web Services Training in Pune
Useful blog admin, keep sharing more like this.
ReplyDeleteWindows Azure course in Chennai
Best Azure Training in Chennai
Robotics Process Automation Training in Chennai
R Programming Training in Chennai
DevOps Certification Chennai
ccna Training in Chennai
Thanks for your contribution in sharing such a useful information. This was really helpful to me. Waiting for your further updates.
ReplyDeleteFrench Class in Mulund
French Coaching in Mulund
French Classes in Mulund East
French Language Classes in Mulund
French Training in Mulund
French Coaching Classes in Mulund
French Classes in Mulund West
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeleteJava training in Chennai | Java training in Tambaram
Java training in Chennai | Java training in Velachery
Java training in Chennai | Java training in Omr
Oracle training in Chennai
Thank you for sharing such a great concept. I got more knowledge from this blog. Your site was amazing. Keep update on some more details...
ReplyDeleteBlue Prism Training Bangalore
Blue Prism Classes in Bangalore
Blue Prism Training Centers in Bangalore
Blue Prism Institute in Bangalore
Blue Prism Training in Perambur
Blue Prism Training in Nolambur
Amazing Post . Thanks for sharing. Your style of writing is very unique. Pls keep on updating.
ReplyDeleteSpoken English Classes in Chennai
Best Spoken English Classes in Chennai
Spoken English Class in Chennai
Spoken English in Chennai
Best Spoken English Class in Chennai
English Coaching Classes in Chennai
Selenium training in chennai
ReplyDeleteSelenium training institute in Chennai
iOS Course Chennai
Digital Marketing Training in Chennai
German Training Institutes in Velachery
German Language Classes in Chennai
German Courses in chennai
Really great information!!! Thanks for your blog.
ReplyDeleteGuest posting sites
Education
Nice article I was really impressed by seeing this blog, it was very interesting and it is very useful for me.
ReplyDeleteJavascript Training in Bangalore
Java script Training in Bangalore
Best Institute for Javascript in Bangalore
Advanced Java Course in Bangalore
Java Coaching Institutes in Bangalore
Good written and great info. Thank you for taking the time to provide us with your valuable information. Please Keep it up...
ReplyDeleteCCNA Training Center in Bangalore
Best CCNA Training Institute in Bangalore
CCNA Certification in Bangalore
CCNA Course in Bangalore
CCNA Training in Nungambakkam
CCNA Course in Kodambakkam
CCNA Training in Aminjikarai
The blog which you have shared is more informative. Thanks for your information.
ReplyDeleteBest Institute for JAVA
Best JAVA Training
JAVA Programming Certification Course
Best JAVA Certification
Best JAVA Training
This comment has been removed by the author.
ReplyDeleteWonderful blog!!! Thanks for your information… Waiting for your upcoming data.
ReplyDeleteEthical Hacking Course in Coimbatore
Hacking Course in Coimbatore
Ethical Hacking Training in Coimbatore
Ethical Hacking Training Institute in Coimbatore
Ethical Hacking Training
Ethical Hacking Course
Thanks for your interesting ideas.the information's in this blog is very much useful
ReplyDeletefor me to improve my knowledge.
Selenium training near me
Selenium Training in Chennai
Selenium Training in Amjikarai
Selenium Training Institutes in Vadapalani
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeletepython course institute in bangalore
python Course in bangalore
python training institute in bangalore
Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
ReplyDeleteData Science course in rajaji nagar
Data Science with Python course in chenni
Data Science course in electronic city
Data Science course in USA
Data science course in pune | Data Science Training institute in Pune
Thank you for provided this content. I learn a lot of information. Please keep it....
ReplyDeleteAutomation Courses in Bangalore
RPA Courses in Bangalore
Robotics Classes in Bangalore
Robotics Training in Bangalore
RPA Training in Bangalore
Robotics Courses in Bangalore
Nice article. I liked very much. All the informations given by you are really helpful for my research. keep on posting your views.
ReplyDeleteCloud computing Training in Chennai
Cloud computing Training
Cloud computing Training near me
Salesforce Developer Training
Salesforce crm Training in Chennai
Salesforce administrator training in chennai
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
ReplyDeleteBest Devops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram
Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging.. Brazilian wax in Manhattan
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleterpa training in Chennai | rpa training in bangalore | best rpa training in bangalore | rpa course in bangalore | rpa training institute in bangalore | rpa training in bangalore | rpa online training
Well done! This is really powerful post and also very interesting. Thanks for your sharing and I want more updates from your blog.
ReplyDeleteDigital Marketing Training in Aminjikarai
Digital Marketing Training in vadapalani
Digital Marketing Course in Chennai
Digital Marketing Training in Omr
Digital Marketing Training in Kelambakkam
Digital Marketing Training in Karappakkam
I’m planning to start my blog soon, but I’m a little lost on everything. Would you suggest starting with a free platform like Word Press or go for a paid option? There are so many choices out there that I’m completely confused. Any suggestions? Thanks a lot.
ReplyDeleteBest AWS Training in Marathahalli | AWS Training in Marathahalli
Best AWS Amazon Web Services Training in Chennai | Best AWS Training and Certification for Solution Architect in Chennai
I am so proud of you and your efforts and work make me realize that anything can be done with patience and sincerity. Well I am here to say that your work has inspired me without a doubt.
ReplyDeleteangularjs Training in bangalore
angularjs Training in bangalore
angularjs interview questions and answers
angularjs Training in marathahalli
angularjs interview questions and answers
angularjs-Training in pune
These super programmers do exist. I've met them. I've lived with them. They live on an unexpected plane in comparison to us unimportant humans. What's more, they all work at Google. how to learn programming Lodi
ReplyDeleteGood writing skill for the author thanks
ReplyDeletebest azure certification training in chennai
Make money on kasino online and do not regret anything gamble casino with us Make money on kaino online and do not regret anything.
ReplyDeletewow great post keep posting new blog
ReplyDeletebest azure certification training chennai
Very nice post here and thanks for it .I always like and such a super contents of these post.
ReplyDeleteExcellent and very cool idea and great content of different kinds of the valuable information's.
Java training in Chennai
Java training in Bangalore
Java online training
Java training in Pune
whatsapp group links
ReplyDeleteAfter reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
ReplyDeleteThank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in
selenium training in Bangalore
selenium training in Marathahalli
selenium training in Btm layout
selenium training in Jaya nagar
selenium training in Electronic city
selenium training in Kalyan nagar
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeletemicrosoft azure training in bangalore
rpa training in bangalore
best rpa training in bangalore
rpa online training
Современная диодная лента по всем стандартам отличного качества я обычно беру у компании Ekodio
ReplyDeleteIt was very informative and the way you write..good and are very helpful... webstagram
ReplyDeleteThis is a really an awesome article which will be informative to everyone.
ReplyDeleteSpoken English Classes in Chennai
Best Spoken English Class in Chennai
German Language Course in Chennai
TOEFL Classes in Chennai
IELTS Coaching centre in Chennai
spanish classes in chennai
Spoken English Classes in Tambaram
Spoken English Classes in Anna Nagar
After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
ReplyDeleteangularjs online training
apache spark online training
informatica mdm online training
devops online training
aws online training
Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
Tremendous effort. Mind-blowing, Extra-ordinary Post. Your post is highly inspirational. Waiting for your future posts.
ReplyDeleteData Analytics Courses in Chennai
Big Data Analytics Courses in Chennai
Data Analytics Courses
Big Data Analytics Training
Big Data Analytics Courses
Data Analytics Certification
Data Analytics Courses in OMR
Data Analytics Courses in Tambaram
Great Post. Extra-ordinary work. Looking for your future blogs.
ReplyDeleteInformatica Training in Chennai
Informatica Training Center Chennai
Informatica course in Chennai
Informatica Training center in Chennai
Informatica Training chennai
Informatica Training institutes in Chennai
Informatica Training in OMR
Informatica Training in Porur
And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
ReplyDeleteC C++ Training in Chennai |Best C C++ Training course in Chennai
linux Training in Chennai | Best linux Training in Chennai
Unix Training in Chennai | Best Unix Training in Chennai
uipath training in chennai | Best uipath training in chennai
Rprogramming Training in Chennai | Best Rprogramming Training in Chennai
ReplyDeleteIt has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
Data Science Training in Chennai | Data Science Course in Chennai
Python Course in Chennai | Python Training Course Institutes in Chennai
RPA Training in Chennai | RPA Training in Chennai
Digital Marketing Course in Chennai | Best Digital Marketing Training in Chennai
This comment has been removed by the author.
ReplyDeleteHome Mart is a site about Home Improvement, Furniture, Home Appliances and many more.
ReplyDeleteCheck out the best
home office desks nz
coffee table nz
bookshelves
Excellent stuff, I really happy to read your great post. Keep it up to the good work...
ReplyDeletePega Training in Chennai
Pega Training Institutes in Chennai
Tableau Training in Chennai
Oracle Training in Chennai
Power BI Training in Chennai
Job Openings in Chennai
Social Media Marketing Courses in Chennai
Spark Training in Chennai
Pega Training in Vadapalani
Pega Training in Thiruvanmiyur
Thanks for sharing the article. Keep sharing your ideas with us.
ReplyDeleteEthical Hacking course in Chennai
Ethical Hacking Training Institute in Chennai
Hacking course in Chennai
ccna Training in Chennai
Salesforce course in Chennai
PHP Training in Chennai
Tally course in Chennai
Ethical Hacking course in OMR
Ethical Hacking course in Anna Nagar
Ethical Hacking course in Vadapalani
Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing.
ReplyDeleteAzure Training in Chennai
Microsoft Azure Training
Machine Learning Training in Chennai
Blue Prism Training in Chennai
AWS Training in Chennai
Automation Anywhere Training in Chennai
Azure course in Velachery
Azure course in Tambaram
Azure Training in Porur
thanks for sharing this informtion
ReplyDeleteBlue Prism Training in Bangalore
Blue Prism Training in BTM
informatica Training in Bangalore
MERN StackTraining in Bangalore
MEAN Stack Training in Bangalore
RPA Training in Bangalore
Qlikview Training in Bangalore
Machine Learning training in bangalore
메이저토토사이트
ReplyDelete
ReplyDeleteThanks for sharing this article. Really helpful for me.
Geo News
Free Forex Signals
Daily Bitcoin Predictions
Thanks very nice article keep up the good work
ReplyDeleteVijay Devarakonda Biography
Rocky Jaiswal Biography
Shehla Rashid Biography
Mayanti Langer Biography
Freelance Website Designer in Delhi
my website
ReplyDeletemy website
my website
my website
my website
my website
Nice information, want to know about Selenium Training In Chennai
ReplyDeleteSelenium Training In Chennai
Data Science Training In Chennai
Protractor Training in Chennai
jmeter training in chennai
Rpa Training Chennai
Rpa Course Chennai
Selenium Training institute In Chennai
Python Training In Chennai
Rpa Training in Chennai
ReplyDeleteRpa Course in Chennai
Blue prism training in Chennai
Data Science Training In Chennai
Data Science Course In Chennai
Data Science Course In Chennai
Really a awesome blog for the freshers. Thanks for posting the information.
ReplyDeletebusiness card price in india
mugs online india
computer rental in chennai
laptop rental near me
incorporation company registration
incorporation of public limited company in india
An inflatable backrest and comfortable seating increases your comfort experience with paddling. The front of the kayak is used entirely to store your stuffs with mesh top.
ReplyDeleteIntex Explorer K2 Kayak 2 Person Inflatable Sit On Top Kayak
Great Article
ReplyDeleteData Mining Projects
Python Training in Chennai
Project Centers in Chennai
Python Training in Chennai
Wow it is really wonderful and awesome thus it is veWow, it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.
ReplyDeletepython training in bangalore
python courses in bangalore
python classes in bangalore
python training institute in bangalore
python course syllabus
best python training
python training centers
This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information.
ReplyDeleteaws training in bangalore
aws courses in bangalore
aws classes in bangalore
aws training institute in bangalore
aws course syllabus
best aws training
aws training centers
It is very good and useful for students and developer.Learned a lot of new things from your post Good creation,thanks for give a good information at sap crm.
ReplyDeletedevops training in bangalore
devops courses in bangalore
devops classes in bangalore
devops training institute in bangalore
devops course syllabus
best devops training
best devops training
Excellent post for the people who really need information for this technology.
ReplyDeletesap simplefinance training in bangalore
sap simplefinance courses in bangalore
sap simplefinance classes in bangalore
sap simplefinance training institute in bangalore
sap simplefinance course syllabus
best sap simplefinance training
sap simplefinance training centers
Great Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
JavaScript Training in Chennai
JavaScript Training in Chennai