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
Solved

MVC 5 Cannot Successfully Add Claim?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell File Sort 8 41
Syntax Issue with SSIS module 26 100
exporting html table data 4 26
How to Generate a Method from a keyboard shortcut in Visual Studio? 2 18
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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