Solved

MVC 5 Cannot Successfully Add Claim?

Posted on 2014-11-18
5
290 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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