Guest User

Untitled

a guest
Jan 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. @{Html.RenderAction("UserInfo", "Account");}
  2.  
  3. public class UserInfo()
  4. {
  5. public bool IsAuthenticated {get;set;}
  6. public string ForeName {get;set;}
  7. }
  8.  
  9. public PartialViewResult UserInfo()
  10. {
  11. var model = new UserInfo();
  12.  
  13. model.IsAutenticated = httpContext.User.Identity.IsAuthenticated;
  14.  
  15. if(model.IsAuthenticated)
  16. {
  17. // Hit the database and retrieve the Forename
  18. model.ForeName = Database.Users.Single(u => u.UserName == httpContext.User.Identity.UserName).ForeName;
  19.  
  20. //Return populated ViewModel
  21. return this.PartialView(model);
  22. }
  23.  
  24. //return the model with IsAuthenticated only
  25. return this.ParitalView(model);
  26. }
  27.  
  28. @model UserInfo
  29.  
  30. @if(Model.IsAuthenticated)
  31. {
  32. <text>Hello, <strong>@Model.ForeName</strong>!
  33. [ @Html.ActionLink("Log Off", "LogOff", "Account") ]
  34. </text>
  35. }
  36. else
  37. {
  38. @:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
  39. }
Add Comment
Please, Sign In to add comment