?
Solved

MVC 5 Cannot Successfully Add Claim?

Posted on 2014-11-18
5
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40452557
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
ID: 40452710
Correct!
0
 
LVL 96

Expert Comment

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

Accepted Solution

by:
WorknHardr earned 0 total points
ID: 40456160
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
ID: 40490906
thx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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