문제

I want to adjust the _LoginPartial.cshtml to display:

Logged in as <username>(<rolename>) | Logoff

So I wish to add the first role name associated with the logged in user.

I can't access it via the user object, so how do I access this information?

This is the current code:

@Html.ActionLink("Logged in as " + User.Identity.GetUserName(), "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
도움이 되었습니까?

해결책

You'll want to use the Role class, but really what you should be doing is collecting this information together in the controller & passing it, probably in the ViewBag. That way your view is abstracted from where you get the username & roles from.

다른 팁

If you're using claims, then you can downcast the User to a ClaimsPrincipal and then filter the Claims collection on the Type == ClaimsTypes.Role.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top