Solved

MVC 5 Cannot Successfully Add Claim?

Posted on 2014-11-18
5
263 Views
Last Modified: 2014-12-10
At least if it is added, I cannot return it to a view.
I'm trying to return a User FullName to the ever popular _LoginPartial.cshtml and having difficuties.
I can however return the built-in properties like so:
@using Microsoft.AspNet.Identity

        var identity = (System.Security.Claims.ClaimsPrincipal)System.Threading.Thread.CurrentPrincipal;
        var claims = identity.Claims;
      
         <ul>
            @foreach (var c in claims)
            {                
                <li>@c</li>
            }
        </ul>

Open in new window


I'm trying to add a new Claim at Login like so:
     var user = await UserManager.FindAsync(model.Email, model.Password);

    ... case SignInStatus.Success:

     var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.GivenName, user.FullName)});
     identity.AddClaim(new Claim(ClaimTypes.GivenName, user.FullName));

   ... return RedirectToLocal(returnUrl);  

Open in new window

0
Comment
Question by:WorknHardr
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I don't understand what you are having a problem with.  Does the identity.Claims list not show the FullName claim?
0
 

Author Comment

by:WorknHardr
Comment Utility
Correct!
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What does show on the view, in the claims list?
0
 

Accepted Solution

by:
WorknHardr earned 0 total points
Comment Utility
Well, ahh, the code was changed and there's no backup to looked at. Seems we're using a Session now like so, which works very well...

[_LoginPartial]
@Html.ActionLink("Hello " + @Session["UserDisplayName"] + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })

[AccountController -> Login]
   case SignInStatus.Success:
                    //NEW
                    var user = await UserManager.FindAsync(model.Email, model.Password);
                    string[] fullName = user.FullName.Split(' ');
                    Session["UserDisplayName"] = fullName[0];
                    //END
                    return RedirectToLocal(returnUrl);
    case...

Open in new window

0
 

Author Closing Comment

by:WorknHardr
Comment Utility
thx
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now