我很好奇使用Identity并在默认EF框架数据库中的aspnetUsers表中保存用户信息。有没有办法将属性呈现给视图,其他用户可以在应用程序运行时同时查看这些属性。我有一个问题,我只是得到当前用户。我需要构建一个用户搜索子系统,它可以显示用户并拥有指向他们个人资料的链接。
例如,我在Identity.Models
中向我的ApplicationUser添加了属性public` string displayName { get; set; }
public string age { get; set; }
public string description { get; set; }
在我的家庭控制器中(我知道它的内容,但我只是测试它是否有效)
公共ActionResult关于() {
// Instantiate the ASP.NET Identity system
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(User.Identity.GetUserId());
// Recover the profile information about the logged in user
ViewBag.displayName = currentUser.displayName;
ViewBag.age = currentUser.age;
ViewBag.description = currentUser.description;
////////
var usr = User.Identity.Name;
// var usrName = ;
ViewBag.Message = usr;
return View();
}
在我的关于视图
中@using Microsoft.AspNet.Identity;
@{
ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
<h3>@ViewBag.displayName</h3>
<h3>@ViewBag.age</h3>
<h3>@ViewBag.description</h3>
我可以看到当前的用户属性,但我试图找出asp.net如何与其他应用程序用户交互以查看其他配置文件?我知道程序正在做我要求它做的事情(将当前用户的属性放在about视图中)但是我不知道下一步该去哪里。
答案 0 :(得分:0)
创建一个ViewModel让我们调用它Dim combo As New ComboBoxHelper(hWnd) 'You have hWnd
MessageBox.Show(combo.ItemsCount.ToString())
MessageBox.Show(combo.SelectedIndex.ToString())
MessageBox.Show(combo.SelectedText.ToString())
combo.Items.ForEach(Function(item) MessageBox.Show(item))
这就是你要在他们的个人资料中显示用户所以用你希望你向用户展示的属性填充它(确保你有任何额外的属性)要添加到ProfileViewModel
,现在有一个用户点击其个人资料页面并希望查看他的个人资料,使用您可以获取其userId的身份,或者您已将其存储在ApplicationUser
或{ {1}}因此,如果2个用户在同一时间点击了个人资料,则每个人都有自己的个人资料,而不是彼此显示(session
)会为您提供userId。
现在,在您的cookie
中,您需要做的是根据User.Identity.GetUserId()
获取ActionResult
的实体,并填写ApplicationUser
中的UserId
并将其传递给您的视图。
这是您获得最新ProfileViewModel
的方式:
ApplicationUser
如何填写你的ProfileViewModel:
ApplicationUser