2017-04-15 147 views
0

这是为我的项目和我寻求帮助,因为我在我的ViewProfile页面在MVC ASP.NET发现困难。如何在asp.net mvc中登录后显示用户信息?

我已成功使用FormsAuthentication,以便在登录后可以显示我的名字,但是我创建了一个ViewProfile的链接,我可以从注册中显示可以从数据库中获取的详细信息。但我无法完成这项工作。有人可以帮我解决这个问题。

我不使用的EntityFramework,顺便说一句...

+0

>我已成功使用了formsauthentication,因此我可以在登录后显示我的名字。但是我已经为ViewProfile创建了一个链接,可以从注册中显示可以从数据库获取的详细信息。但我无法完成这项工作。什么不工作? – Krishna

回答

0

您可以通过使用此代码

//// // 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.description = currentUser.UserName; 

,并在您的视图

<h3>@ViewBag.description</h3> 

得到的信息,你必须使用usermanager这为我工作,但记住这只显示信息。

相关问题