Instead of using user name, I want to display the value from column DisplayName which exists in my ApplicationUser class.
Based on the solution here, I created a custom class and initialize it in Global.asax Application Start.
public class UserProfileActionFilter: ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
if (user != null)
{
filterContext.Controller.ViewBag.DisplayName = user.DisplayName;
}
}
}
I then refer following ViewBag.DisplayName in the LogOnPartialView.
But this class is being hit multiple times through out the application, during login, action execution and etc. I'm worried if this will cause overhead to the database.