2017-04-15 592 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這爲我工作,但記住這隻顯示信息。