You should save the topic name / url as a claim against the user, and not as part of the User class:
await userManager.AddClaimAsync(user.Id, new Claim("MyApp:ThemeUrl", "~/Content/bootstrap.flatly.min.css"));
When a user logs in, this claim is added to the cookie and you can access it through the extension method:
public static String GetThemeUrl(this ClaimsPrincipal principal) { var themeClaim = principal.Claims.FirstOrDefault(c => c.Type == "MyApp:ThemeUrl"); if (themeClaim != null) { return themeClaim.Value; } // return default theme url if no claim is set return "path/to/default/theme"; }
and in your opinion, you will get access to the theme URL as follows:
<link href="@ClaimsPrincipal.Current.GetThemeUrl()" rel="stylesheet" />
Claims about the principle are available in a cookie, therefore, no additional database deletions are required.
Alternatively, you can save the BootstrapTheme user as you already did, but when the user logs in, add this topic as a claim to the id:
public async Task SignInAsync(IAuthenticationManager authenticationManager, ApplicationUser applicationUser, bool isPersistent) { authenticationManager.SignOut( DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.ApplicationCookie); var identity = await this.CreateIdentityAsync(applicationUser, DefaultAuthenticationTypes.ApplicationCookie); identity.AddClaim(new Claim("MyApp:ThemeUrl", applicationUser.BootstrapTheme)); authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
And then access the application in the presentation through the above extension method. I recently wrote a blog post about a similar scenario - you can look there to find out more about how complaints work.
trailmax Aug 19 '14 at 13:39 on 2014-08-19 13:39
source share