Reputation: 507
I am extending an existing MVC web application which uses ASP.NET Identity for authentication. It uses System.Web.HttpContext.Current.User.Identity.Name
for getting the username of the currently logged on user.
When I switch to OWIN authentication using the sample code explained here the Name
property is null, causing the existing application to throw an error. Is it possible to change the value of IIdentity.Name
without invalidating the identity?
Upvotes: 1
Views: 3403
Reputation: 14634
As described at the bottom of the referenced tutorial, you should access the user claims via the ClaimsPrincipal.Current
object, such as:
// Controllers\HomeController.cs
[Authorize]
public ActionResult Claims()
{
Claim displayName = ClaimsPrincipal.Current.FindFirst(ClaimsPrincipal.Current.Identities.First().NameClaimType);
ViewBag.DisplayName = displayName != null ? displayName.Value : string.Empty;
return View();
}
Upvotes: 1