Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:27:32+00:00 2026-06-11T22:27:32+00:00

I’ve got my claims set-up with MVC3 using azure and everything is going well.

  • 0

I’ve got my claims set-up with MVC3 using azure and everything is going well.

What I need to do now is extend the Claims Identity that’s in the current thread / http context and add my own information (DOB, Address.. that sort of stuff)

so my question is – where is the best place to do this? any examples would be great..

I presume that when the user is authenticated id then have to go to the DB and pull back the relevant record for the user then add it to the custom Claims Identity object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:27:33+00:00Added an answer on June 11, 2026 at 10:27 pm

    Typically you will have a httpmodule that will inspect the cookies and once the FedAuth token is found, you have a hook to build your Claims Principal and identities.

    You don’t typically need to store the user’s entire profile, just useful things that wont typically change that often. I do this inside of an actionfilter.

    Here is the code I found that does all of this.

    https://github.com/wcpro/ScaffR/tree/master/src/ScaffR.Security/content/CodeTemplates/Scaffolders/ScaffR.Security

    You may have to do a little digging but its all there.

    Here is the code for the http module

    public class ClaimsTransformationHttpModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PostAuthenticateRequest += context_PostAuthenticateRequest;
        }
    
        void context_PostAuthenticateRequest(object sender, EventArgs e)
        {
            var context = ((HttpApplication) sender).Context;
    
            if (FederatedAuthentication.SessionAuthenticationModule != null &&
                FederatedAuthentication.SessionAuthenticationModule.ContainsSessionTokenCookie(context.Request.Cookies))
            {
                return;
            }
    
            var transformer = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager;
    
            if (transformer != null)
            {
                var transformedPrincipal = transformer.Authenticate(context.Request.RawUrl, context.User as ClaimsPrincipal);
    
                context.User = transformedPrincipal;
                Thread.CurrentPrincipal = transformedPrincipal;
            }
        }
    
        public void Dispose() { }
    }
    

    Here is the Claims Transformer

        public partial class ClaimsTransformer : ClaimsAuthenticationManager
    {
        partial void SetCustomPrincipalClaims(IUserService userService, ref ClaimsPrincipal principal);
    
        public override ClaimsPrincipal Authenticate(string resourceName, ClaimsPrincipal incomingPrincipal)
        {
            if (!incomingPrincipal.Identity.IsAuthenticated)
            {
                return incomingPrincipal;
            }
    
            var newPrincipal = Transform(incomingPrincipal);
    
            EstablishSession(newPrincipal);
    
            return newPrincipal;
        }
    
        ClaimsPrincipal Transform(ClaimsPrincipal incomingPrincipal)
        {
            var nameClaim = incomingPrincipal.Identities.First().FindFirst(ClaimTypes.Name);
    
            var userService = DependencyResolver.Current.GetService<IUserService>();
    
            var user = userService.GetByUsername(nameClaim.Value);
    
            var id = new ApplicationIdentity(user);
    
            var principal = new ClaimsPrincipal(id);
    
            SetCustomPrincipalClaims(userService, ref principal);
    
            return principal;
        }        
    
        private void EstablishSession(ClaimsPrincipal principal)
        {
            if (HttpContext.Current != null)
            {
                var sessionToken = new SessionSecurityToken(principal);
                FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(sessionToken);
            }
        }
    }
    

    Then here is the configuration

    <?xml version="1.0" encoding="utf-8"?>
    <system.identityModel>
      <identityConfiguration>
        <claimsAuthenticationManager type="Barbarella.Core.Common.Security.ClaimsTransformer, Barbarella.Core" />
      </identityConfiguration>
    </system.identityModel>
    

    And this…

        <system.identityModel.services>
      <federationConfiguration>
        <cookieHandler mode="Default" requireSsl="false" />
      </federationConfiguration>
    </system.identityModel.services>
    

    And this…

    <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ClaimsTransformationModule" type="Barbarella.Core.Common.Security.ClaimsTransformationHttpModule, Barbarella.Core" />
      <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    
    </modules>
    

    Dont forget to add your configuration sections

        <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    

    Here is my code for the ApplicationIdentity (overrides ClaimsIDentity)… This is the code that answers your question really…

     public sealed partial class ApplicationIdentity : ClaimsIdentity
    {
        partial void SetCustomIdentityClaims(User user);
    
        private readonly User _user;
    
        public ApplicationIdentity(User user) : base("Application")
        {
            _user = user;
            AddClaim(new Claim(ClaimTypes.Name, user.Username));     
            AddClaim(new Claim(ApplicationClaimTypes.UserId, user.Id.ToString(CultureInfo.InvariantCulture)));
            AddClaim(new Claim(ApplicationClaimTypes.FirstName, user.FirstName));
            AddClaim(new Claim(ApplicationClaimTypes.LastName, user.LastName));
            AddClaim(new Claim("Time", DateTime.Now.ToString()));
    
            SetCustomIdentityClaims(_user);
        }
    
        public User User
        {
            get { return _user; }
        }
    
        public int UserId
        {
            get { return int.Parse(FindFirst(ApplicationClaimTypes.UserId).Value); }
        }
    
        public string Username
        {
            get { return FindFirst(ClaimTypes.Name).Value; }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.